What's New / App UI: SwiftUI, AppKit & UIKit

What's new in WebKit

+39 NewiOS · macOS · visionOS

WebKit is Apple's web rendering engine, exposed through WKWebView and its delegate protocols for loading, navigating, and scripting web content. It also handles cookies and JavaScript message handlers.

The 27 SDK adds 39 APIs, with no deprecations or removals. New types cover an immersive-environment path for web content: ImmersiveEnvironment, WebViewImmersiveEnvironmentView, the WKImmersiveEnvironmentDelegate protocol, and a FormInfo struct. Other additions include getCookies, world, nodeSerializationEnabled, jsHandleCreationEnabled, mainFrameNavigation, and new webView overloads on WKNavigationDelegate and WKUIDelegate.

New

39
func

add

NewiOSmacOSvisionOS
open func add(_ buffer: WKJSScriptingBuffer, name: String, contentWorld world: WKContentWorld)
var

allowsImmersiveEnvironments

NewvisionOS
open var allowsImmersiveEnvironments: Bool
var

allowsJSHandleCreationInPageWorld

NewiOSmacOSvisionOS
open var allowsJSHandleCreationInPageWorld: Bool
var

alternateRequest

NewiOSmacOSvisionOS
open var alternateRequest: URLRequest?
func

dismissImmersiveEnvironment

NewvisionOS
open func dismissImmersiveEnvironment(completionHandler: @escaping @MainActor @Sendable () -> Void)
func

dismissImmersiveEnvironment

NewvisionOS
open func dismissImmersiveEnvironment() async
func

getCookies

NewiOSmacOSvisionOS
open func getCookies(for url: URL, completionHandler: @escaping @MainActor @Sendable ([HTTPCookie]) -> Void)
func

getCookies

NewiOSmacOSvisionOS
open func getCookies(for url: URL) async -> [HTTPCookie]
var

immersiveEnvironmentDelegate

NewvisionOS
weak open var immersiveEnvironmentDelegate: (any WKImmersiveEnvironmentDelegate)?
var

jsHandleCreationEnabled

NewiOSmacOSvisionOS
open var jsHandleCreationEnabled: Bool
func

load

NewiOSmacOSvisionOS
open func load(_ url: URL) -> WKNavigation?
var

mainFrameNavigation

NewiOSmacOSvisionOS
open var mainFrameNavigation: WKNavigation? { get }
var

nodeSerializationEnabled

NewiOSmacOSvisionOS
open var nodeSerializationEnabled: Bool
var

overrideReferrer

NewiOSmacOSvisionOS
open var overrideReferrer: String?
var

refreshController

NewmacOS
open var refreshController: NSRefreshController?
func

removeBuffer

NewiOSmacOSvisionOS
open func removeBuffer(withName name: String, contentWorld world: WKContentWorld)
extension

WebPage.FormInfo

NewiOSmacOSvisionOS
extension WebPage.FormInfo : Sendable
Declaration
extension WebPage.FormInfo : Sendable {
}
struct

WebViewImmersiveEnvironmentView

NewvisionOS
public struct WebViewImmersiveEnvironmentView : View

A SwiftUI view that renders a specific website-provided immersive environment.

Place this view in your app's Immersive Space hierarchy. Initialize it with the WebPage.ImmersiveEnvironment received from the presentation callback to render that specific environment.

Declaration
@MainActor public struct WebViewImmersiveEnvironmentView : View {

    /// Creates an immersive environment view from a ``WebPage/ImmersiveEnvironment``.
    @MainActor public init(_ environment: WebPage.ImmersiveEnvironment)

    /// Creates an immersive environment view from a `WKImmersiveEnvironment`.
    @MainActor public init(_ environment: WKImmersiveEnvironment)

    /// The content and behavior of the view.
    ///
    /// When you implement a custom view, you must implement a computed
    /// `body` property to provide the content for your view. Return a view
    /// that's composed of built-in views that SwiftUI provides, plus other
    /// composite views that you've already defined:
    ///
    ///     struct MyView: View {
    ///         var body: some View {
    ///             Text("Hello, World!")
    ///         }
    ///     }
    ///
    /// For more information about composing views and a view hierarchy,
    /// see <doc:Declaring-a-Custom-View>.
    @MainActor @preconcurrency public var body: some View { get }

    /// The type of view representing the body of this view.
    ///
    /// When you create a custom view, Swift infers this type from your
    /// implementation of the required ``View/body-swift.property`` property.
    @available(visionOS 27.0, *)
    @available(macOS, unavailable, introduced: 9999)
    @available(iOS, unavailable, introduced: 9999)
    @available(tvOS, unavailable)
    @available(watchOS, unavailable)
    public typealias Body = some View
}
extension

WebViewImmersiveEnvironmentView

NewvisionOS
extension WebViewImmersiveEnvironmentView : Sendable
Declaration
extension WebViewImmersiveEnvironmentView : Sendable {
}
protocol

WKImmersiveEnvironmentDelegate

NewvisionOS
public protocol WKImmersiveEnvironmentDelegate : NSObjectProtocol
Declaration
@MainActor public protocol WKImmersiveEnvironmentDelegate : NSObjectProtocol {

    /** @abstract Asks the delegate whether to allow an immersive environment from the specified frame.
     @param webView The web view that received the immersive environment request.
     @param frame The frame information from the website requesting the immersive environment.
     @param completionHandler The completion handler you must invoke with the request's answer. `YES` to allow
     the environment presentation, or `NO` to deny it.
     */
    @available(visionOS 27.0, *)
    func webView(_ webView: WKWebView, shouldAllowImmersiveEnvironmentFromFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void)

    /** @abstract Asks the delegate whether to allow an immersive environment from the specified frame.
     @param webView The web view that received the immersive environment request.
     @param frame The frame information from the website requesting the immersive environment.
     @param completionHandler The completion handler you must invoke with the request's answer. `YES` to allow
     the environment presentation, or `NO` to deny it.
     */
    @available(visionOS 27.0, *)
    func webView(_ webView: WKWebView, shouldAllowImmersiveEnvironmentFrom frame: WKFrameInfo) async -> Bool

    /** @abstract Asks the delegate to present an immersive environment.
     @param webView The web view requesting presentation.
     @param environment The immersive environment to present.
     @param completionHandler The completion handler you must invoke once the presentation transition has completed.
     The error argument should be used in case the presentation failed and the environment couldn't be presented.
     */
    @available(visionOS 27.0, *)
    func webView(_ webView: WKWebView, present environment: WKImmersiveEnvironment, completionHandler: @escaping ((any Error)?) -> Void)

    /** @abstract Asks the delegate to present an immersive environment.
     @param webView The web view requesting presentation.
     @param environment The immersive environment to present.
     @param completionHandler The completion handler you must invoke once the presentation transition has completed.
     The error argument should be used in case the presentation failed and the environment couldn't be presented.
     */
    @available(visionOS 27.0, *)
    func webView(_ webView: WKWebView, presentImmersiveEnvironment environment: WKImmersiveEnvironment) async throws

    /** @abstract Asks the delegate to dismiss an immersive environment.
     @param webView The web view requesting dismissal.
     @param environment The immersive environment to dismiss.
     @param completionHandler The completion handler you must invoke once the dismissal transition has completed.
     */
    @available(visionOS 27.0, *)
    func webView(_ webView: WKWebView, dismiss environment: WKImmersiveEnvironment, completionHandler: @escaping () -> Void)

    /** @abstract Asks the delegate to dismiss an immersive environment.
     @param webView The web view requesting dismissal.
     @param environment The immersive environment to dismiss.
     @param completionHandler The completion handler you must invoke once the dismissal transition has completed.
     */
    @available(visionOS 27.0, *)
    func webView(_ webView: WKWebView, dismissImmersiveEnvironment environment: WKImmersiveEnvironment) async
}
func

world

NewiOSmacOSvisionOS
open class func world(with configuration: WKContentWorldConfiguration) -> WKContentWorld
func

View.onWebViewImmersiveEnvironmentRequest

NewvisionOS
nonisolated public func onWebViewImmersiveEnvironmentRequest(shouldAllow: @escaping @MainActor @Sendable (_ sourceFrame: WebPage.FrameInfo) async -> Bool, present: @escaping @MainActor @Sendable (_ environment: WebPage.ImmersiveEnvironment) async throws -> Void, dismiss: @escaping @MainActor @Sendable (_ environment: WebPage.ImmersiveEnvironment) async -> Void) -> some View

Manages the lifecycle of immersive environments requested by websites.

Use this modifier to control authorization, presentation, and dismissal of immersive environments from websites.

Parameters

shouldAllow
An async closure called when a website requests an immersive environment. This can be used to request user consent or apply custom authorization logic. It receives the source WebPage.FrameInfo and should return true to allow the environment presentation, or false to deny it.
present
An async throwing closure called after the environment has loaded and is ready for presentation. It receives the WebPage.ImmersiveEnvironment. Use this to open an Immersive Space containing a WebViewImmersiveEnvironmentView initialized with this environment. If another immersive space is already being presented, dismiss it first. This closure should return after the presentation transition completes.
dismiss
An async closure called when the website or the application asks to dismiss the immersive environment. It receives the WebPage.ImmersiveEnvironment to dismiss. This closure should return after the dismissal transition completes.

ReturnsA modified view that manages immersive environment lifecycle.

struct

WebPage.FormInfo

NewiOSmacOSvisionOS
public struct FormInfo

A type that contains information about a form submission from a webpage.

Declaration
@MainActor public struct FormInfo {

    /// The frame where the form is being submitted will cause a navigation.
    @MainActor public var targetFrame: WebPage.FrameInfo { get }

    /// The frame that caused the form submission.
    @MainActor public var sourceFrame: WebPage.FrameInfo { get }

    /// The URL that the frame is being navigated to.
    @MainActor public var submissionURL: URL { get }

    /// The HTTP method used to submit the form; generally either @"GET" or @"POST".
    @MainActor public var httpMethod: String { get }

    /// A dictionary of the form values that will be submitted during the navigation.
    @MainActor public var formValues: [String : String] { get }
}
struct

WebPage.ImmersiveEnvironment

NewvisionOS
public struct ImmersiveEnvironment : Sendable

An object representing a website-provided immersive environment that is ready for presentation.

Declaration
@MainActor public struct ImmersiveEnvironment : Sendable {

    /// The frame information of the website that provided this immersive environment.
    @MainActor public var sourceFrame: WebPage.FrameInfo { get }
}
var

WebPage.Configuration.allowsImmersiveEnvironments

NewvisionOS
public var allowsImmersiveEnvironments: Bool

Indicates whether website immersive environments are allowed.

Set this property to true to enable support for website immersive environments. If false, requests to present immersive environments are ignored. If true, requests are routed through the onWebViewImmersiveEnvironmentRequest view modifier callbacks.

The default value is false.

func

WebPage.NavigationDeciding.willSubmit

NewiOSmacOSvisionOS
mutating func willSubmit(formInfo: WebPage.FormInfo) async

Allow the application to process form autofill information before a form submission actually takes place.

This is an informative callback only. The form values cannot be changed, nor can the navigation be changed to not submit a form.

The form submission will not actually proceed until after this callback asynchronously resolves.

Parameters

formInfo
The form values that will be submitted for this navigation
func

WebPage.NavigationDeciding.willSubmit

NewiOSmacOSvisionOS
public func willSubmit(formInfo: WebPage.FormInfo) async

By default, this method does nothing.

var

WebPage.NavigationPreferences.alternateRequest

NewiOSmacOSvisionOS
public var alternateRequest: URLRequest?

Used to make changes to the network request that will be used for this navigation's main resource load.

var

WebPage.NavigationPreferences.overrideReferrer

NewiOSmacOSvisionOS
public var overrideReferrer: String?

Used to apply a custom referer header to all resource loads in the frame of this navigation.

typealias

WebViewImmersiveEnvironmentView.Body

NewvisionOS
public typealias Body = some View

The type of view representing the body of this view.

When you create a custom view, Swift infers this type from your implementation of the required body-swift.property property.

func

WKImmersiveEnvironmentDelegate.webView

NewvisionOS
func webView(_ webView: WKWebView, shouldAllowImmersiveEnvironmentFromFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void)
func

WKImmersiveEnvironmentDelegate.webView

NewvisionOS
func webView(_ webView: WKWebView, shouldAllowImmersiveEnvironmentFrom frame: WKFrameInfo) async -> Bool
func

WKImmersiveEnvironmentDelegate.webView

NewvisionOS
func webView(_ webView: WKWebView, present environment: WKImmersiveEnvironment, completionHandler: @escaping ((any Error)?) -> Void)
func

WKImmersiveEnvironmentDelegate.webView

NewvisionOS
func webView(_ webView: WKWebView, presentImmersiveEnvironment environment: WKImmersiveEnvironment) async throws
func

WKImmersiveEnvironmentDelegate.webView

NewvisionOS
func webView(_ webView: WKWebView, dismiss environment: WKImmersiveEnvironment, completionHandler: @escaping () -> Void)
func

WKImmersiveEnvironmentDelegate.webView

NewvisionOS
func webView(_ webView: WKWebView, dismissImmersiveEnvironment environment: WKImmersiveEnvironment) async
func

WKNavigationDelegate.webView

NewiOSmacOSvisionOS
optional func webView(_ webView: WKWebView, willSubmitForm formInfo: WKFormInfo, submissionHandler: @escaping @MainActor @Sendable () -> Void)
func

WKNavigationDelegate.webView

NewiOSmacOSvisionOS
optional func webView(_ webView: WKWebView, willSubmitForm formInfo: WKFormInfo) async
func

WKUIDelegate.webView

NewiOSmacOSvisionOS
optional func webView(_ webView: WKWebView, requestGeolocationPermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, decisionHandler: @escaping @MainActor @Sendable (WKPermissionDecision) -> Void)

No APIs match your filter.

← More in App UI: SwiftUI, AppKit & UIKit