<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebPage",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "s:6WebKit0A4PageC"
  },
  "title" : "WebPage"
}
-->

# WebPage

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

```
@MainActor final class WebPage
```

## Overview

A [`WebPage`](/documentation/WebKit/WebPage) is an <doc://com.apple.documentation/documentation/Observation/Observable> type, which you use to access various properties of web content
and track changes to them. Use [`WebPage`](/documentation/WebKit/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:

```swift
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`](/documentation/WebKit/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`](/documentation/WebKit/WebPage/NavigationDeciding) protocol. You can also use the [`backForwardList`](/documentation/WebKit/WebPage/backForwardList-swift.property)
property to observe changes to people’s navigation history, and to programmatically navigate to a
specific back-forward list item.

[`WebPage`](/documentation/WebKit/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:)`](/documentation/WebKit/WebPage/exported(as:)).

## Topics

### Creating a WebPage

[`WebPage.Configuration`](/documentation/WebKit/WebPage/Configuration)

A configuration type that specifies the preferences and behaviors of a webpage.

[`init(configuration:)`](/documentation/WebKit/WebPage/init(configuration:))

Create a new WebPage.

[`init(configuration:dialogPresenter:)`](/documentation/WebKit/WebPage/init(configuration:dialogPresenter:))

Create a new WebPage.

[`init(configuration:navigationDecider:)`](/documentation/WebKit/WebPage/init(configuration:navigationDecider:))

Create a new WebPage.

[`init(configuration:navigationDecider:dialogPresenter:)`](/documentation/WebKit/WebPage/init(configuration:navigationDecider:dialogPresenter:))

Create a new WebPage.

### Managing navigation between webpages

[`WebPage.NavigationDeciding`](/documentation/WebKit/WebPage/NavigationDeciding)

Allows providing custom behavior to handle navigation changes and to coordinate these changes for the web page’s main page.

[`WebPage.NavigationAction`](/documentation/WebKit/WebPage/NavigationAction)

An object that contains information about an action that causes navigation to occur.

[`WebPage.NavigationResponse`](/documentation/WebKit/WebPage/NavigationResponse)

An object that contains the response to a navigation request, and which you use to make navigation-related policy decisions.

[`WebPage.NavigationPreferences`](/documentation/WebKit/WebPage/NavigationPreferences)

A type that specifies the behaviors to use when loading and rendering page content.

[`backForwardList`](/documentation/WebKit/WebPage/backForwardList-swift.property)

The webpage’s back-forward list.

[`WebPage.FrameInfo`](/documentation/WebKit/WebPage/FrameInfo)

A type that contains information about a frame on a webpage.

### Observing navigation between webpages

[`WebPage.BackForwardList`](/documentation/WebKit/WebPage/BackForwardList-swift.struct)

An observable representation of a webpage’s previously loaded resources.

[`WebPage.NavigationEvent`](/documentation/WebKit/WebPage/NavigationEvent)

A particular state that occurs during the progression of a navigation.

[`navigations`](/documentation/WebKit/WebPage/navigations)

A sequence of all the navigation events that occur throughout the webpage, including both user navigation
and programmatic navigation.

[`WebPage.NavigationError`](/documentation/WebKit/WebPage/NavigationError)

A specific error that caused a navigation to fail.

### Configuring a WebPage

[`WebPage.Configuration`](/documentation/WebKit/WebPage/Configuration)

A configuration type that specifies the preferences and behaviors of a webpage.

[`WebPage.DeviceSensorAuthorization`](/documentation/WebKit/WebPage/DeviceSensorAuthorization)

A type that describes the authorization permissions policy for the device’s sensors a web resource may access.

[`URLScheme`](/documentation/WebKit/URLScheme)

A type representing a valid URL scheme.

[`URLSchemeHandler`](/documentation/WebKit/URLSchemeHandler)

A protocol for loading resources with URL schemes that WebKit doesn’t handle.

[`URLSchemeTaskResult`](/documentation/WebKit/URLSchemeTaskResult)

A value used as part of a sequence of results from a [`URLSchemeHandler`](/documentation/WebKit/URLSchemeHandler), which can either be a `Data` or a `URLResponse`.

### Loading web content

[`load(_:)`](/documentation/WebKit/WebPage/load(_:)-32ngj)

Navigates to an item from the back-forward list and sets it as the current item.

[`load(_:)`](/documentation/WebKit/WebPage/load(_:)-7kw3h)

Loads the web content that the specified URL request object references and navigates to that content.

[`load(_:)`](/documentation/WebKit/WebPage/load(_:)-8wfiq)

Loads the web content that the specified URL references and navigates to that content.

[`load(_:mimeType:characterEncoding:baseURL:)`](/documentation/WebKit/WebPage/load(_:mimeType:characterEncoding:baseURL:))

Loads the content of the specified data object and navigates to it.

[`load(html:baseURL:)`](/documentation/WebKit/WebPage/load(html:baseURL:))

Loads the contents of the specified HTML string and navigates to it.

[`load(simulatedRequest:responseHTML:)`](/documentation/WebKit/WebPage/load(simulatedRequest:responseHTML:))

Loads the web content from the HTML you provide as if the HTML were the response to the request.

[`load(simulatedRequest:response:responseData:)`](/documentation/WebKit/WebPage/load(simulatedRequest:response:responseData:))

Loads the web content from the data you provide as if the data were the response to the request.

[`isLoading`](/documentation/WebKit/WebPage/isLoading)

Indicates whether the webpage is currently loading content.

[`estimatedProgress`](/documentation/WebKit/WebPage/estimatedProgress)

An estimate of completion percentage of the current navigation.

### Managing the loading process

[`reload(fromOrigin:)`](/documentation/WebKit/WebPage/reload(fromOrigin:))

Reloads the current webpage.

[`stopLoading()`](/documentation/WebKit/WebPage/stopLoading())

Stops loading all resources on the current page.

### Inspecting page information

[`WebPage.CSSMediaType`](/documentation/WebKit/WebPage/CSSMediaType)

A CSS media type as defined by the [CSS specification](https://www.w3.org/TR/mediaqueries-4/#media-types), or an arbitrary media type value.

[`title`](/documentation/WebKit/WebPage/title)

The page title.

[`url`](/documentation/WebKit/WebPage/url)

The URL for the current webpage.

[`mediaType`](/documentation/WebKit/WebPage/mediaType)

The media type for the contents of the webpage.

[`customUserAgent`](/documentation/WebKit/WebPage/customUserAgent)

The custom user agent string.

[`serverTrust`](/documentation/WebKit/WebPage/serverTrust)

The trust management object you use to evaluate trust for the current webpage.

[`hasOnlySecureContent`](/documentation/WebKit/WebPage/hasOnlySecureContent)

Indicates whether the webpage loaded all resources on the page through securely encrypted connections.

[`themeColor`](/documentation/WebKit/WebPage/themeColor)

The theme color that the system gets from the first valid meta tag in the webpage.

[`isBlockedByScreenTime`](/documentation/WebKit/WebPage/isBlockedByScreenTime)

Indicates whether Screen Time blocking has occurred.

[`isInspectable`](/documentation/WebKit/WebPage/isInspectable)

Indicates whether you can inspect the page with Safari Web Inspector.

[`isWritingToolsActive`](/documentation/WebKit/WebPage/isWritingToolsActive)

Indicates whether Writing Tools is active for the page.

### Executing JavaScript

[`callJavaScript(_:arguments:in:contentWorld:)`](/documentation/WebKit/WebPage/callJavaScript(_:arguments:in:contentWorld:))

Executes the specified string as an async JavaScript function.

### Customizing JavaScript dialogs

[`WebPage.DialogPresenting`](/documentation/WebKit/WebPage/DialogPresenting)

Allows providing custom behavior to handle JavaScript actions and provide a response.

[`WebPage.FileInputPromptResult`](/documentation/WebKit/WebPage/FileInputPromptResult)

The result of handling a JavaScript open invocation.

[`WebPage.JavaScriptConfirmResult`](/documentation/WebKit/WebPage/JavaScriptConfirmResult)

The result of handling a JavaScript confirm invocation.

[`WebPage.JavaScriptPromptResult`](/documentation/WebKit/WebPage/JavaScriptPromptResult)

The result of handling a JavaScript confirm invocation.

### Exporting webpage content

[`WebPage.ExportedContentConfiguration`](/documentation/WebKit/WebPage/ExportedContentConfiguration)

A specialized configuration of a specific exportable type that can have specific properties unique to the content type.

[`exported(as:)`](/documentation/WebKit/WebPage/exported(as:))

Using the type’s `Transferable` conformance implementation, exports a value as binary data,
optionally with a specified configuration for that type of data.

### Interacting with media

[`WebPage.FullscreenState`](/documentation/WebKit/WebPage/FullscreenState-swift.enum)

The set of possible fullscreen states a webpage may be in.

[`pauseAllMediaPlayback()`](/documentation/WebKit/WebPage/pauseAllMediaPlayback())

Pauses playback of all media in the web view.

[`mediaPlaybackState()`](/documentation/WebKit/WebPage/mediaPlaybackState())

Determine the playback status of media in the page.

[`setAllMediaPlaybackSuspended(_:)`](/documentation/WebKit/WebPage/setAllMediaPlaybackSuspended(_:))

Changes whether the webpage is suspending playback of all media in the page.

[`closeAllMediaPresentations()`](/documentation/WebKit/WebPage/closeAllMediaPresentations())

Closes all media the webpage is presenting, including picture-in-picture video and fullscreen video.

[`fullscreenState`](/documentation/WebKit/WebPage/fullscreenState-swift.property)

The fullscreen state the page is currently in.

### Managing the microphone and camera

[`cameraCaptureState`](/documentation/WebKit/WebPage/cameraCaptureState)

Indicates whether the webpage is using the camera to capture images or video.

[`microphoneCaptureState`](/documentation/WebKit/WebPage/microphoneCaptureState)

Indicates whether the webpage is using the microphone to capture audio.

[`setCameraCaptureState(_:)`](/documentation/WebKit/WebPage/setCameraCaptureState(_:))

Changes whether the webpage is using the camera to capture images or video.

[`setMicrophoneCaptureState(_:)`](/documentation/WebKit/WebPage/setMicrophoneCaptureState(_:))

Changes whether the webpage is using the microphone to capture audio.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)