interface WebViewProviderService {
    getWebViewProvider: ((webViewType: string) => Promise<IRegisteredWebViewProvider | undefined>);
    initialize: (() => Promise<void>);
    postMessageToWebView: ((webViewId: string, webViewNonce: string, message: unknown, targetOrigin?: string) => Promise<void>);
    registerWebViewController: (<WebViewType>(webViewType: WebViewType, webViewId: string, webViewController: WebViewControllers[WebViewType]) => Promise<DisposableNetworkObject<WebViewControllers[WebViewType]>>);
    registerWebViewProvider: ((webViewType: string, webViewProvider: IWebViewProvider) => Promise<IDisposableWebViewProvider>);
}

Properties

getWebViewProvider: ((webViewType: string) => Promise<IRegisteredWebViewProvider | undefined>)

Type declaration

    • (webViewType): Promise<IRegisteredWebViewProvider | undefined>
    • Get a web view provider that has previously been set up

      Parameters

      • webViewType: string

        Type of webview provider to get

      Returns Promise<IRegisteredWebViewProvider | undefined>

      Web view provider with the given name if one exists, undefined otherwise

initialize: (() => Promise<void>)

Type declaration

    • (): Promise<void>
    • Sets up the service. Only runs once and always returns the same promise after that

      Returns Promise<void>

postMessageToWebView: ((webViewId: string, webViewNonce: string, message: unknown, targetOrigin?: string) => Promise<void>)

Type declaration

    • (webViewId, webViewNonce, message, targetOrigin?): Promise<void>
    • Sends a message to the specified web view. Expected to be used only by the IWebViewProvider that created the web view or the WebViewControllers that represents the web view created by the Web View Provider.

      postMessage is used to deliver the message to the web view iframe. The web view can use window.addEventListener("message", ...) in order to receive these messages.

      Parameters

      • webViewId: string

        Id of the web view to which to send a message.

      • webViewNonce: string

        Nonce used to perform privileged interactions with the web view. Pass in the nonce the web view provider received from IWebViewProvider.getWebView's webViewNonce parameter or from WebViewFactory.createWebViewController's webViewNonce parameter

      • message: unknown

        Data to send to the web view. Can only send serializable information

      • OptionaltargetOrigin: string

        Expected origin of the web view. Does not send the message if the web view's origin does not match. See postMessage's targetOrigin for more information. Defaults to same origin only (works automatically with React and HTML web views)

      Returns Promise<void>

registerWebViewController: (<WebViewType>(webViewType: WebViewType, webViewId: string, webViewController: WebViewControllers[WebViewType]) => Promise<DisposableNetworkObject<WebViewControllers[WebViewType]>>)

Type declaration

    • <WebViewType>(webViewType, webViewId, webViewController): Promise<DisposableNetworkObject<WebViewControllers[WebViewType]>>
    • Register a web view controller to represent a web view. It is expected that a web view provider calls this to register a web view controller for a web view that is being created. If a web view provider extends WebViewFactory, it will call this function automatically.

      A Web View Controller is a network object that represents a web view and whose methods facilitate communication between its associated web view and extensions that want to interact with it.

      You can get web view controllers with webViewService.getWebViewController.

      Type Parameters

      Parameters

      • webViewType: WebViewType

        Type of web view for which you are providing this web view controller

      • webViewId: string

        Id of web view for which to register the web view controller

      • webViewController: WebViewControllers[WebViewType]

        Object to register as a web view controller including control over disposing of it. Note: the web view controller will be disposed automatically when the web view is closed

        WARNING: setting a web view controller mutates the provided object.

      Returns Promise<DisposableNetworkObject<WebViewControllers[WebViewType]>>

      webViewController modified to be a network object

registerWebViewProvider: ((webViewType: string, webViewProvider: IWebViewProvider) => Promise<IDisposableWebViewProvider>)

Type declaration

    • (webViewType, webViewProvider): Promise<IDisposableWebViewProvider>
    • Register a web view provider to serve webViews for a specified type of webViews

      Parameters

      • webViewType: string

        Type of web view to provide

      • webViewProvider: IWebViewProvider

        Object to register as a webView provider including control over disposing of it.

        WARNING: setting a webView provider mutates the provided object.

      Returns Promise<IDisposableWebViewProvider>

      webViewProvider modified to be a network object and able to be disposed with dispose