Contents

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.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.

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