다음을 통해 공유


CoreWebView2Environment Class

Definition

This represents the WebView2 Environment.

public class CoreWebView2Environment
type CoreWebView2Environment = class
Public Class CoreWebView2Environment
Inheritance
CoreWebView2Environment

Remarks

WebViews created from an environment run on the Browser process specified with environment parameters and objects created from an environment should be used in the same environment. Using it in different environments are not guaranteed to be compatible and may fail.

Properties

BrowserVersionString

Gets the browser version info of the current CoreWebView2Environment, including channel name if it is not the stable channel.

FailureReportFolderPath

Gets the failure report folder that all CoreWebView2s created from this environment are using.

LoaderDllFolderPath

The relative or absolute folder's path where WebView2Loader.dll exists. If LoaderDllFolderPath is set, we will load %LoaderDllFolderPath%\WebView2Loader.dll first.

RenderAdapterLUID

The graphics adapter LUID of the renderer. The host should use this LUID adapter when creating D3D device to use with CreateTextureStream().

UserDataFolder

Gets the user data folder that all CoreWebView2s created from this environment are using.

Methods

CompareBrowserVersions(String, String)

Compares two instances of browser versions correctly and returns an integer that indicates whether the first instance is older, the same as, or newer than the second instance.

CreateAsync(String, String, CoreWebView2EnvironmentOptions)

Creates a WebView2 Environment using the installed or a custom WebView2 Runtime version.

CreateContextMenuItem(String, Stream, CoreWebView2ContextMenuItemKind)

Create a custom CoreWebView2ContextMenuItem object to insert into the WebView context menu.

CreateCoreWebView2CompositionControllerAsync(IntPtr, CoreWebView2ControllerOptions)

Create a new WebView in visual hosting mode with options.

CreateCoreWebView2CompositionControllerAsync(IntPtr)

Asynchronously creates a new WebView for use with visual hosting.

CreateCoreWebView2CompositionControllerWithOptionsAsync(IntPtr, CoreWebView2ControllerOptions)

Create a new webview in visual hosting mode with CoreWebView2ControllerOptions as parameter for multiple profiles support.

CreateCoreWebView2ControllerAsync(IntPtr, CoreWebView2ControllerOptions)

Create a new WebView with options.

CreateCoreWebView2ControllerAsync(IntPtr)

Asynchronously creates a new WebView.

CreateCoreWebView2ControllerOptions()

Creates a new CoreWebView2ControllerOptions object, which can be passed as a parameter in CreateCoreWebView2ControllerAsync(IntPtr, CoreWebView2ControllerOptions) and CreateCoreWebView2CompositionControllerAsync(IntPtr, CoreWebView2ControllerOptions) function for multiple profiles support.

CreateCoreWebView2ControllerOptions(String, Int32)

Create a new CoreWebView2ControllerOptions object, which can be passed as a parameter in CreateCoreWebView2ControllerAsync(IntPtr, CoreWebView2ControllerOptions) and CreateCoreWebView2CompositionControllerAsync(IntPtr, CoreWebView2ControllerOptions) function for multiple profiles support.

CreateCoreWebView2ControllerWithOptionsAsync(IntPtr, CoreWebView2ControllerOptions)

Create a new webview with CoreWebView2ControllerOptions as parameter for multiple profiles support.

CreateCoreWebView2PointerInfo()

Creates an empty CoreWebView2PointerInfo.

CreatePrintSettings()

Creates the CoreWebView2PrintSettings used by the PrintToPdfAsync(String, CoreWebView2PrintSettings) method.

CreateSharedBuffer(UInt64)

Create a shared memory based buffer with the specified size in bytes.

CreateTextureStream(String, Object)

Registers the stream id that the host can handle, providing a texture stream when requested from the WebView2's JavaScript code. The host can register multiple unique stream instances, each with a unique stream ID, enabling the host to stream from different sources concurrently. The host should call this only once for unique streamId. The second call of already created streamId without destroying CoreWebView2TextureStream object will return an error. d3dDevice is used for creating shared IDXGI resource and NT shared of it. The host should use Adapter of the LUID from the GetRenderAdapterLUID for creating the D3D Device.

CreateWebFileSystemDirectoryHandle(String, CoreWebView2FileSystemHandlePermission)

Create a ICoreWebView2FileSystemHandle object from a path that represents a Web FileSystemDirectoryHandle.

        The `path` is the path pointed by the directory and must be a syntactically correct fully qualified
        path, but it is not checked here whether it currently points to a directory. Any other state
        validation will be done when this handle is accessed from web content
        and will cause DOM exceptions if access operations fail. If an invalid path is
        passed, an E_INVALIDARG will be returned and the object will fail to create.

        `Permission` property is used to specify whether the Handle should be created with a Read-only or
        Read-and-write web permission. For the `permission` value specified here, the Web
        [PermissionStatus](https://developer.mozilla.org/docs/Web/API/PermissionStatus)
        will be [granted](https://developer.mozilla.org/docs/Web/API/PermissionStatus/state)
        and the unspecified permission will be
        [prompt](https://developer.mozilla.org/docs/Web/API/PermissionStatus/state). Therefore,
        the web content then does not need to call
        [requestPermission](https://developer.mozilla.org/docs/Web/API/FileSystemHandle/requestPermission)
        for the permission that was specified before attempting the permitted operation,
        but if it does, the promise will immediately be resolved
        with 'granted' PermissionStatus without firing the WebView2
        [PermissionRequested](/microsoft-edge/webview2/reference/win32/icorewebview2permissionrequestedeventargs)
        event or prompting the user for permission. Otherwise, `requestPermission` will behave as the
        status of permission is currently `Prompt`, which means the `PermissionRequested` event will fire
        or the user will be prompted.
        Additionally, the app must have the same OS permissions that have propagated to the
        [WebView2 browser process](/microsoft-edge/webview2/concepts/process-model)
        for the path it wishes to give the web content to make any operations on the directory.
        Specifically, the WebView2 browser process will run in same user, package identity, and app
        container of the app, but other means such as security context impersonations do not get
        propagated, so such permissions that the app has, will not be effective in WebView2.
        Note: An exception to this is, if there is a parent directory handle that
        has broader permissions in the same page context than specified in here, the handle will automatically
        inherit the most permissive permission of the parent handle when posted to that page context.
        i.e. If there is already a `FileSystemDirectoryHandle` to `C:\example` that has write permission on
        a page, even though a WebFileSystemHandle to directory `C:\example\directory` is created with
        `COREWEBVIEW2_FILE_SYSTEM_HANDLE_PERMISSION_READ_ONLY` permission, when posted to that page, write permission
        will be automatically granted to the created handle.

        An app needs to be mindful that this object, when posted to the web content, provides it with unusual
        access to OS file system via the Web FileSystem API! The app should therefore only post objects
        for paths that it wants to allow access to the web content and it is not recommended that the web content
        "asks" for this path. The app should also check the source property of the target to ensure
        that it is sending to the web content of intended origin.

        Once the object is passed to web content, the path must point to a directory as if it was chosen via
        [directory picker](https://developer.mozilla.org/docs/Web/API/Window/showDirectoryPicker)
        otherwise any IO operation done on the `FileSystemDirectoryHandle` will throw a DOM exception.
CreateWebFileSystemFileHandle(String, CoreWebView2FileSystemHandlePermission)

Create a ICoreWebView2FileSystemHandle object from a path that represents a Web FileSystemFileHandle.

        The `path` is the path pointed by the file and must be a syntactically correct fully qualified
        path, but it is not checked here whether it currently points to a file. If an invalid path is
        passed, an E_INVALIDARG will be returned and the object will fail to create. Any other state
        validation will be done when this handle is accessed from web content
        and will cause the DOM exceptions described in
        [FileSystemFileHandle methods](https://developer.mozilla.org/docs/Web/API/FileSystemDirectoryHandle#instance_methods)
        if access operations fail.

        `Permission` property is used to specify whether the Handle should be created with a Read-only or
        Read-and-write web permission. For the `permission` value specified here, the DOM
        [PermissionStatus](https://developer.mozilla.org/docs/Web/API/PermissionStatus) property
        will be [granted](https://developer.mozilla.org/docs/Web/API/PermissionStatus/state)
        and the unspecified permission will be
        [prompt](https://developer.mozilla.org/docs/Web/API/PermissionStatus/state). Therefore,
        the web content then does not need to call
        [requestPermission](https://developer.mozilla.org/docs/Web/API/FileSystemHandle/requestPermission)
        for the permission that was specified before attempting the permitted operation,
        but if it does, the promise will immediately be resolved
        with 'granted' PermissionStatus without firing the WebView2
        [PermissionRequested](/microsoft-edge/webview2/reference/win32/icorewebview2permissionrequestedeventargs)
        event or prompting the user for permission. Otherwise, `requestPermission` will behave as the
        status of permission is currently `prompt`, which means the `PermissionRequested` event will fire
        or the user will be prompted.
        Additionally, the app must have the same OS permissions that have propagated to the
        [WebView2 browser process](/microsoft-edge/webview2/concepts/process-model)
        for the path it wishes to give the web content to read/write the file.
        Specifically, the WebView2 browser process will run in same user, package identity, and app
        container of the app, but other means such as security context impersonations do not get
        propagated, so such permissions that the app has, will not be effective in WebView2.
        Note: An exception to this is, if there is a parent directory handle that
        has broader permissions in the same page context than specified in here, the handle will automatically
        inherit the most permissive permission of the parent handle when posted to that page context.
        i.e. If there is already a `FileSystemDirectoryHandle` to `C:\example` that has write permission on
        a page, even though a WebFileSystemHandle to file `C:\example\file.txt` is created with
        `COREWEBVIEW2_FILE_SYSTEM_HANDLE_PERMISSION_READ_ONLY` permission, when posted to that page, write permission
        will be automatically granted to the created handle.

        An app needs to be mindful that this object, when posted to the web content, provides it with unusual
        access to OS file system via the Web FileSystem API! The app should therefore only post objects
        for paths that it wants to allow access to the web content and it is not recommended that the web content
        "asks" for this path. The app should also check the source property of the target to ensure
        that it is sending to the web content of intended origin.

        Once the object is passed to web content, if the content is attempting a read,
        the file must be existing and available to read similar to a file chosen by
        [open file picker](https://developer.mozilla.org/docs/Web/API/Window/showOpenFilePicker),
        otherwise the read operation will
        [throw a DOM exception](https://developer.mozilla.org/docs/Web/API/FileSystemFileHandle/getFile#exceptions).
        For write operations, the file does not need to exist as `FileSystemFileHandle` will behave
        as a file path chosen by
        [save file picker](https://developer.mozilla.org/docs/Web/API/Window/showSaveFilePicker)
        and will create or overwrite the file, but the parent directory structure pointed
        by the file must exist and an existing file must be available to write and delete
        or the write operation will
        [throw a DOM exception](https://developer.mozilla.org/docs/Web/API/FileSystemFileHandle/createWritable#exceptions).
CreateWebResourceRequest(String, String, Stream, String)

Creates a new CoreWebView2WebResourceRequest object.

CreateWebResourceResponse(Stream, Int32, String, String)

Creates a new CoreWebView2WebResourceResponse object.

GetAutomationProviderForWindow(IntPtr)

Returns the UI Automation Provider for the CoreWebView2CompositionController that corresponds with the given hwnd.

GetAvailableBrowserVersionString(String, CoreWebView2EnvironmentOptions)

Gets the browser version info including channel name if it is not the stable channel or WebView2 Runtime.

GetAvailableBrowserVersionString(String)

Gets the browser version info including channel name if it is not the stable channel or WebView2 Runtime.

GetProcessExtendedInfosAsync()

Returns a snapshot collection of CoreWebView2ProcessInfo corresponding to all currently running processes associated with this CoreWebView2Environment excludes crashpad process. This provides the same list of CoreWebView2ProcessInfo as what's provided in GetProcessInfos(), but additionally provides a list of associated CoreWebView2FrameInfo which are actively running (showing or hiding UI elements) in the renderer process. See AssociatedFrameInfos for more information.

GetProcessInfos()

Returns the list of all CoreWebView2ProcessInfo using same user data folder except for crashpad process.

GetProcessInfosWithDetailsAsync()

Returns a snapshot collection of CoreWebView2ProcessInfo corresponding to all currently running processes associated with this CoreWebView2Environment excludes crashpad process. This provides the same list of CoreWebView2ProcessInfo as what's provided in GetProcessInfos(), but additionally provides a list of associated CoreWebView2FrameInfo which are actively running (showing or hiding UI elements) in the renderer process. See AssociatedFrameInfos for more information.

GetProviderForHwnd(IntPtr)

Returns the UI Automation Provider for the CoreWebView2CompositionController that corresponds with the given hwnd.

SetLoaderDllFolderPath(String)

Set the path of the folder containing the WebView2Loader.dll.

UpdateRuntimeAsync()

Try to update the installed Microsoft Edge WebView2 Runtime.

Events

BrowserProcessExited

BrowserProcessExited is raised when the collection of WebView2 Runtime processes for the browser process of this CoreWebView2Environment terminate due to browser process failure or normal shutdown (for example, when all associated WebViews are closed), after all resources have been released (including the user data folder).

NewBrowserVersionAvailable

NewBrowserVersionAvailable is raised when a newer version of the WebView2 Runtime is installed and available using WebView2.

ProcessInfosChanged

ProcessInfosChanged is raised when a collection of WebView2 Runtime processes changed due to new process being detected or when a existing process gone away.

RenderAdapterLUIDChanged

Listens for change of graphics adapter LUID of the browser. The host can get the updated LUID by RenderAdapterLUID. It is expected that the host updates texture's d3d Device with SetD3DDevice, removes existing textures and creates new texture.

RestartRequested

Add an event handler for the RestartRequested event. RestartRequested event is raised when there is a need to restart WebView2 process in order to apply certain beneifical updates.

RestartRequested gives developers the awareness of these necessary WebView2 restarts, allowing developers to resolve issues faster than waiting for end users to restart the app. Developer might want to give end users the ability to save their state before restarting. For apps with multiple processes that host WebView2s that share the same user data folder you need to make sure all WebView2 instances are closed and the associated WebView2 Runtime browser process exits. See BrowserProcessExited for more details.

Applies to