Share via


WebUIView Class

Definition

Represents a view (window) of the app to the application background script.

public ref class WebUIView sealed : IWebViewControl, IWebViewControl2
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 458752)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class WebUIView final : IWebViewControl, IWebViewControl2
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 458752)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class WebUIView : IWebViewControl, IWebViewControl2
Public NotInheritable Class WebUIView
Implements IWebViewControl, IWebViewControl2
Inheritance
Object Platform::Object IInspectable WebUIView
Attributes
Implements

Windows requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v7.0)

Examples

Your app can listen for the NewWebUIViewCreated event to intercept control of the navigation for a new view (exposed from NewWebUIEventCreatedEventArgs.WebUIView):

Windows.UI.WebUI.WebUIApplication.addEventListener("newwebuiviewcreated", newWebUIViewCreatedEventHandler);

Remarks

Windows 10 web apps support an optional per-application background script that starts before any views are activated and runs for the duration of the process. With this, you can monitor and modify navigations, track state across navigations, monitor navigation errors, and run code before views are activated.

When this background script is specified as the StartPage in your app manifest, each of the app's views (windows) are exposed to the script as instances of the WebUIView class, providing the same events, properties, and methods as a general (Win32) WebView.

There are several differences between the HTML webview (x-ms-webview/MSHTMLWebViewElement) and the WebUIView class:

  HTML webview WebUIView class
WebUIView async methods Return MSWebViewAsyncOperation objects Return JavaScript promise objects
Navigate method Requires a URI in the form of a string Requires a Windows.Foundation.Uri object
InvokeScriptAsync method Script arguments are specified as an arbitrary number of string parameters Script arguments are specified as an array of strings

Any app activation with the background script as the StartPage will rely on the script itself for navigation.

Properties

ApplicationViewId

Gets the identifier for this view.

CanGoBack

Gets a value that indicates whether there is at least one page in the backward navigation history.

CanGoForward

Gets a value that indicates whether there is at least one page in the forward navigation history.

ContainsFullScreenElement

Gets a value that indicates whether the view contains an element that supports full screen.

DefaultBackgroundColor

Gets or sets the color to use as the view background when the HTML content does not specify a color.

DeferredPermissionRequests

Gets a collection of permission requests that are waiting to be granted or denied.

DocumentTitle

Gets the title of the page currently displayed in the view.

IgnoreApplicationContentUriRulesNavigationRestrictions

Gets or sets a value that specifies whether to ignore content URI rules and navigation restrictions.

Settings

Gets a WebViewControlSettings object that contains properties to enable or disable IWebViewControl features.

Source

Gets or sets the URI source of the HTML content to display in the control.

Methods

AddInitializeScript(String)

Adds a script to initialize the view.

BuildLocalStreamUri(String, String)

Creates a URI that you can pass to NavigateToLocalStreamUri

CapturePreviewToStreamAsync(IRandomAccessStream)

Creates an image of the current view contents and writes it to the specified stream.

CaptureSelectedContentToDataPackageAsync()

Asynchronously gets a DataPackage that contains the selected content within the control.

CreateAsync()

Creates a new view as an asynchronous action.

CreateAsync(Uri)

Creates a new view with specific arguments, as an asynchronous action.

GetDeferredPermissionRequestById(UInt32, WebViewControlDeferredPermissionRequest)

Returns the deferred permission request with the specified Id.

GoBack()

Navigates to the previous page in the navigation history.

GoForward()

Navigates to the next page in the navigation history.

InvokeScriptAsync(String, IIterable<String>)

Executes the specified script function from the currently loaded HTML, with specific arguments, as an asynchronous action.

Navigate(Uri)

Loads the HTML content at the specified Uniform Resource Identifier (URI).

NavigateToLocalStreamUri(Uri, IUriToStreamResolver)

Loads local web content at the specified URI using an IUriToStreamResolver.

NavigateToString(String)

Loads the specified HTML content as a new document.

NavigateWithHttpRequestMessage(HttpRequestMessage)

Navigates the control to a URI with a POST request and HTTP headers.

Refresh()

Reloads the current content in the control.

Stop()

Halts the current control navigation or download.

Events

Activated

Occurs when the view is activated.

Closed

Occurs when the view has been closed.

ContainsFullScreenElementChanged

Occurs when the status of whether the view currently contains a full screen element or not changes.

ContentLoading

Occurs when the view starts loading new content.

DOMContentLoaded

An event that is triggered when the view has finished parsing the current HTML content.

FrameContentLoading

Occurs when a frame in the view begins loading new content.

FrameDOMContentLoaded

Occurs when a frame in the view has finished parsing its current HTML content.

FrameNavigationCompleted

Occurs when the control has finished loading the current content or if the navigation has failed.

FrameNavigationStarting

Occurs just before the view navigates to new content.

LongRunningScriptDetected

An event that is triggered periodically while the control executes JavaScript, letting you halt the script.

NavigationCompleted

Occurs when the control has finished loading the current content or if the navigation has failed.

NavigationStarting

Occurs before the control navigates to new content.

NewWindowRequested

Occurs when a user performs an action in the control that causes content to be opened in a new window.

PermissionRequested

Occurs when an action in the control requires that permission to be granted.

ScriptNotify

Occurs when the content contained in the control passes a string to the app using JavaScript.

UnsafeContentWarningDisplaying

Occurs when the control shows a warning page for content that was reported as unsafe by SmartScreen Filter.

UnsupportedUriSchemeIdentified

Occurs when an attempt is made to navigate to a URI using a scheme that the control doesn't support.

UnviewableContentIdentified

An event that is triggered when the control attempts to download an unsupported file.

WebResourceRequested

An event that is fired when an HTTP request is made.

Applies to