onWebViewImmersiveEnvironmentRequest(shouldAllow:present:dismiss:)
Manages the lifecycle of immersive environments requested by websites.
Declaration
nonisolated func onWebViewImmersiveEnvironmentRequest(shouldAllow: @escaping @MainActor @Sendable (WebPage.FrameInfo) async -> Bool, present: @escaping @MainActor @Sendable (WebPage.ImmersiveEnvironment) async throws -> Void, dismiss: @escaping @MainActor @Sendable (WebPage.ImmersiveEnvironment) async -> Void) -> some View
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.FrameInfoand should returntrueto allow the environment presentation, orfalseto 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 aWebViewImmersiveEnvironmentViewinitialized 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.ImmersiveEnvironmentto dismiss. This closure should return after the dismissal transition completes.
Return Value
A modified view that manages immersive environment lifecycle.
Discussion
Use this modifier to control authorization, presentation, and dismissal of immersive environments from websites.
See Also
Displaying web content
WebViewWebPagewebViewBackForwardNavigationGestures(_:)webViewContentBackground(_:)webViewContextMenu(menu:)webViewElementFullscreenBehavior(_:)webViewLinkPreviews(_:)webViewMagnificationGestures(_:)webViewOnScrollGeometryChange(for:of:action:)webViewScrollInputBehavior(_:for:)webViewScrollPosition(_:)webViewTextSelection(_:)