Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
This reference is no longer being maintained. For the latest API reference, see WebView2 API Reference.
interface ICoreWebView2_29
: public ICoreWebView2_28
A continuation of the ICoreWebView2 interface to manage dedicated workers.
Summary
| Members | Descriptions |
|---|---|
| add_DedicatedWorkerCreated | Adds an event handler for the DedicatedWorkerCreated event. |
| remove_DedicatedWorkerCreated | Removes an event handler previously added with add_DedicatedWorkerCreated. |
Applies to
| Product | Introduced |
|---|---|
| WebView2 Win32 | N/A |
| WebView2 Win32 Prerelease |
Members
add_DedicatedWorkerCreated
Adds an event handler for the DedicatedWorkerCreated event.
public HRESULT add_DedicatedWorkerCreated(ICoreWebView2DedicatedWorkerCreatedEventHandler * eventHandler, EventRegistrationToken * token)
Subscribe to this event that gets raised when a new dedicated worker is created.
A Dedicated Worker is a type of web worker that allows you to run Javascript code in the background without blocking the main thread, making them useful for tasks like heavy computations, data processing, and parallel execution. It is "dedicated" because it is linked to a single parent document and cannot be shared with other scripts.
This event is raised when a web application creates a dedicated worker using the new Worker("/worker.js") method. See the Worker for more information.
m_appWindow->GetWebView()->QueryInterface(IID_PPV_ARGS(&m_webView2_29));
CHECK_FEATURE_RETURN_EMPTY(m_webView2_29);
CHECK_FAILURE(m_webView2_29->add_DedicatedWorkerCreated(
Callback<ICoreWebView2DedicatedWorkerCreatedEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2DedicatedWorkerCreatedEventArgs* args)
{
wil::com_ptr<ICoreWebView2DedicatedWorker> dedicatedWorker;
CHECK_FAILURE(args->get_Worker(&dedicatedWorker));
wil::unique_cotaskmem_string scriptUri;
CHECK_FAILURE(dedicatedWorker->get_ScriptUri(&scriptUri));
std::wstring scriptUriStr(scriptUri.get());
m_appWindow->AsyncMessageBox(scriptUriStr, L"Dedicated worker is created");
// Subscribe to worker destroying event
dedicatedWorker->add_Destroying(
Callback<ICoreWebView2DedicatedWorkerDestroyingEventHandler>(
[this, scriptUriStr](
ICoreWebView2DedicatedWorker* sender, IUnknown* args) -> HRESULT
{
/*Cleanup on worker destruction*/
m_appWindow->AsyncMessageBox(
scriptUriStr, L"Dedicated worker is destroyed");
return S_OK;
})
.Get(),
nullptr);
return S_OK;
})
.Get(),
&m_dedicatedWorkerCreatedToken));
remove_DedicatedWorkerCreated
Removes an event handler previously added with add_DedicatedWorkerCreated.
public HRESULT remove_DedicatedWorkerCreated(EventRegistrationToken token)