---
title: WebPage
framework: webkit
role: symbol
role_heading: Class
path: webkit/webpage
---

# WebPage

An object that controls and manages the behavior of interactive web content.

## Declaration

```swift
@MainActor final class WebPage
```

## Overview

Overview A WebPage is an Observable type, which you use to access various properties of web content and track changes to them. Use WebPage to interact with web content, like evaluating JavaScript or converting the page to PDF data. The following example shows you how you can combine these capabilities to get specific metadata from an ephemeral page with a custom user agent: func fetchMetadata(for url: URL) async throws -> (title: String, description: String) {     let botAgent = """     Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0     """

var configuration = WebPage.Configuration()     configuration.loadsSubresources = false     configuration.defaultNavigationPreferences.allowsContentJavaScript = false     configuration.websiteDataStore = .nonPersistent()

// Set up the configured page.

let page = WebPage(configuration: configuration)     page.customUserAgent = botAgent

// Load the request and wait for navigation to complete.

let request = URLRequest(url: url)     for try await event in page.load(request) {         // Optionally do something with `event`.     }

// At this point, the navigation is complete.     // Now, use JavaScript to query the appropriate properties of the page.

let fetchOpenGraphProperty = """     const propertyValues = document.querySelectorAll(`meta[property="${property}"]`);     return propertyValues[0];     """

let javaScriptResult = try await page.callJavaScript(fetchOpenGraphProperty, arguments: arguments)     guard let description = javaScriptResult as? String else {         // Handle failure, like throwing an error.     }

guard let title = page.title else {         // Handle failure, like throwing an error.     }

return (title, description) } Use WebPage to programmatically navigate to various types of resources like URL requests, HTML strings, and data. Optionally, you can observe these navigations through the async sequence returned by their associated loading functions, and you can customize them by using a type that conforms to the WebPage.NavigationDeciding protocol. You can also use the backForwardList property to observe changes to people’s navigation history, and to programmatically navigate to a specific back-forward list item. WebPage also conforms to the Transferable protocol. You can use this conformance to export the page to various different types of content, like PDF, web archive data, and other types. For customization of PDF or image exprt, use exported(as:).

## Topics

### Creating a WebPage

- [WebPage.Configuration](webkit/webpage/configuration.md)
- [init(configuration:)](webkit/webpage/init(configuration:).md)
- [init(configuration:dialogPresenter:)](webkit/webpage/init(configuration:dialogpresenter:).md)
- [init(configuration:navigationDecider:)](webkit/webpage/init(configuration:navigationdecider:).md)
- [init(configuration:navigationDecider:dialogPresenter:)](webkit/webpage/init(configuration:navigationdecider:dialogpresenter:).md)

### Managing navigation between webpages

- [WebPage.NavigationDeciding](webkit/webpage/navigationdeciding.md)
- [WebPage.NavigationAction](webkit/webpage/navigationaction.md)
- [WebPage.NavigationResponse](webkit/webpage/navigationresponse.md)
- [WebPage.NavigationPreferences](webkit/webpage/navigationpreferences.md)
- [backForwardList](webkit/webpage/backforwardlist-swift.property.md)
- [WebPage.FrameInfo](webkit/webpage/frameinfo.md)

### Observing navigation between webpages

- [WebPage.BackForwardList](webkit/webpage/backforwardlist-swift.struct.md)
- [WebPage.NavigationEvent](webkit/webpage/navigationevent.md)
- [navigations](webkit/webpage/navigations.md)
- [WebPage.NavigationError](webkit/webpage/navigationerror.md)

### Configuring a WebPage

- [WebPage.Configuration](webkit/webpage/configuration.md)
- [WebPage.DeviceSensorAuthorization](webkit/webpage/devicesensorauthorization.md)
- [URLScheme](webkit/urlscheme.md)
- [URLSchemeHandler](webkit/urlschemehandler.md)
- [URLSchemeTaskResult](webkit/urlschemetaskresult.md)

### Loading web content

- [load(_:)](webkit/webpage/load(_:)-32ngj.md)
- [load(_:)](webkit/webpage/load(_:)-7kw3h.md)
- [load(_:)](webkit/webpage/load(_:)-8wfiq.md)
- [load(_:mimeType:characterEncoding:baseURL:)](webkit/webpage/load(_:mimetype:characterencoding:baseurl:).md)
- [load(html:baseURL:)](webkit/webpage/load(html:baseurl:).md)
- [load(simulatedRequest:responseHTML:)](webkit/webpage/load(simulatedrequest:responsehtml:).md)
- [load(simulatedRequest:response:responseData:)](webkit/webpage/load(simulatedrequest:response:responsedata:).md)
- [isLoading](webkit/webpage/isloading.md)
- [estimatedProgress](webkit/webpage/estimatedprogress.md)

### Managing the loading process

- [reload(fromOrigin:)](webkit/webpage/reload(fromorigin:).md)
- [stopLoading()](webkit/webpage/stoploading().md)

### Inspecting page information

- [WebPage.CSSMediaType](webkit/webpage/cssmediatype.md)
- [title](webkit/webpage/title.md)
- [url](webkit/webpage/url.md)
- [mediaType](webkit/webpage/mediatype.md)
- [customUserAgent](webkit/webpage/customuseragent.md)
- [serverTrust](webkit/webpage/servertrust.md)
- [hasOnlySecureContent](webkit/webpage/hasonlysecurecontent.md)
- [themeColor](webkit/webpage/themecolor.md)
- [isBlockedByScreenTime](webkit/webpage/isblockedbyscreentime.md)
- [isInspectable](webkit/webpage/isinspectable.md)
- [isWritingToolsActive](webkit/webpage/iswritingtoolsactive.md)

### Executing JavaScript

- [callJavaScript(_:arguments:in:contentWorld:)](webkit/webpage/calljavascript(_:arguments:in:contentworld:).md)

### Customizing JavaScript dialogs

- [WebPage.DialogPresenting](webkit/webpage/dialogpresenting.md)
- [WebPage.FileInputPromptResult](webkit/webpage/fileinputpromptresult.md)
- [WebPage.JavaScriptConfirmResult](webkit/webpage/javascriptconfirmresult.md)
- [WebPage.JavaScriptPromptResult](webkit/webpage/javascriptpromptresult.md)

### Exporting webpage content

- [WebPage.ExportedContentConfiguration](webkit/webpage/exportedcontentconfiguration.md)
- [exported(as:)](webkit/webpage/exported(as:).md)

### Interacting with media

- [WebPage.FullscreenState](webkit/webpage/fullscreenstate-swift.enum.md)
- [pauseAllMediaPlayback()](webkit/webpage/pauseallmediaplayback().md)
- [mediaPlaybackState()](webkit/webpage/mediaplaybackstate().md)
- [setAllMediaPlaybackSuspended(_:)](webkit/webpage/setallmediaplaybacksuspended(_:).md)
- [closeAllMediaPresentations()](webkit/webpage/closeallmediapresentations().md)
- [fullscreenState](webkit/webpage/fullscreenstate-swift.property.md)

### Managing the microphone and camera

- [cameraCaptureState](webkit/webpage/cameracapturestate.md)
- [microphoneCaptureState](webkit/webpage/microphonecapturestate.md)
- [setCameraCaptureState(_:)](webkit/webpage/setcameracapturestate(_:).md)
- [setMicrophoneCaptureState(_:)](webkit/webpage/setmicrophonecapturestate(_:).md)

### Structures

- [WebPage.FormInfo](webkit/webpage/forminfo.md)
- [WebPage.ImmersiveEnvironment](webkit/webpage/immersiveenvironment.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [Observable](observation/observable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Transferable](coretransferable/transferable.md)

## See Also

### Essentials

- [Building a cross-platform web browser](webkit/building-a-cross-platform-web-browser.md)
- [WebView](webkit/webview-swift.struct.md)
