WorkerGlobalScope Class

The global object of a worker (https://html.spec.whatwg.org/multipage/workers.html#the-workerglobalscope-common-interface): a DedicatedWorkerGlobalScope or a SharedWorkerGlobalScope. A worker runs its own event loop on its own thread, and its scripts run in the realm of its own script engine (ScriptEngine.CreateWorkerScriptEngine): the members of a worker global scope must be used on the thread of the worker.

public abstract class WorkerGlobalScope : GlobalScope
Inheritance
GlobalScope WorkerGlobalScope

Properties

NameDescription
CrossOriginIsolatedhttps://html.spec.whatwg.org/multipage/webappapis.html#dom-crossoriginisolated: a dedicated worker has the cross-origin isolated capability of its owner (except a worker created from a data: URL); a shared worker is isolated when its embedder policy is compatible with cross-origin isolation (https://html.spec.whatwg.org/multipage/workers.html#run-a-worker).
FontsThe font source of the worker (https://drafts.csswg.org/css-font-loading/#font-source): the font faces created by the scripts of the worker and added to the set, which the text of its OffscreenCanvas objects uses once they are loaded. A worker has no CSS-connected font face.
IsSecureContexthttps://html.spec.whatwg.org/multipage/webappapis.html#dom-issecurecontext: the creator of the worker is a secure context, and the URL of the worker is potentially trustworthy (or a data: or blob: URL).
Locationhttps://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-location
NameGets the name of the worker (https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-name).
Navigatorhttps://html.spec.whatwg.org/multipage/workers.html#dom-worker-navigator
OnErrorGets or sets the event handler of the error event.
OnLanguageChangeGets or sets the event handler of the languagechange event.
OnOfflineGets or sets the event handler of the offline event.
OnOnlineGets or sets the event handler of the online event.
OnRejectionHandledGets or sets the event handler of the rejectionhandled event.
OnUnhandledRejectionGets or sets the event handler of the unhandledrejection event.
Originhttps://html.spec.whatwg.org/multipage/webappapis.html#dom-origin
Selfhttps://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-self
TrustedTypeshttps://w3c.github.io/trusted-types/dist/spec/#dom-windoworworkerglobalscope-trustedtypes: the trusted type policy factory of the worker. Trusted Types are enforced by the require-trusted-types-for and trusted-types directives of the CSP list of the worker (the policies of the response of its script, or the ones of its creator for a worker whose URL is a local scheme).

CrossOriginIsolated

WorkerGlobalScope.cs

https://html.spec.whatwg.org/multipage/webappapis.html#dom-crossoriginisolated: a dedicated worker has the cross-origin isolated capability of its owner (except a worker created from a data: URL); a shared worker is isolated when its embedder policy is compatible with cross-origin isolation (https://html.spec.whatwg.org/multipage/workers.html#run-a-worker).

public override bool CrossOriginIsolated { get; }

The font source of the worker (https://drafts.csswg.org/css-font-loading/#font-source): the font faces created by the scripts of the worker and added to the set, which the text of its OffscreenCanvas objects uses once they are loaded. A worker has no CSS-connected font face.

public FontFaceSet Fonts { get; }

IsSecureContext

WorkerGlobalScope.cs

https://html.spec.whatwg.org/multipage/webappapis.html#dom-issecurecontext: the creator of the worker is a secure context, and the URL of the worker is potentially trustworthy (or a data: or blob: URL).

public override bool IsSecureContext { get; }

https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-location

public WorkerLocation Location { get; }

Gets the name of the worker (https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-name).

public string Name { get; }

Property value

string

Gets or sets the event handler of the error event.

public Action<Event>? OnError { get; set; }

OnLanguageChange

WorkerGlobalScope.cs

Gets or sets the event handler of the languagechange event.

public Action<Event>? OnLanguageChange { get; set; }

Gets or sets the event handler of the offline event.

public Action<Event>? OnOffline { get; set; }

Gets or sets the event handler of the online event.

public Action<Event>? OnOnline { get; set; }

OnRejectionHandled

WorkerGlobalScope.cs

Gets or sets the event handler of the rejectionhandled event.

public Action<Event>? OnRejectionHandled { get; set; }

OnUnhandledRejection

WorkerGlobalScope.cs

Gets or sets the event handler of the unhandledrejection event.

public Action<Event>? OnUnhandledRejection { get; set; }

https://html.spec.whatwg.org/multipage/webappapis.html#dom-origin

public override string Origin { get; }

https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-self

public WorkerGlobalScope Self { get; }

https://w3c.github.io/trusted-types/dist/spec/#dom-windoworworkerglobalscope-trustedtypes: the trusted type policy factory of the worker. Trusted Types are enforced by the require-trusted-types-for and trusted-types directives of the CSP list of the worker (the policies of the response of its script, or the ones of its creator for a worker whose URL is a local scheme).

public TrustedTypePolicyFactory TrustedTypes { get; }

Methods

NameDescription
ImportScripts(IEnumerable<object>)Runs the scripts of urls synchronously, in order, in the realm of the worker (https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-importscripts).
ImportScripts(string[])Runs the scripts of urls synchronously, in order, in the realm of the worker (https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-importscripts). The exceptions of the scripts are rethrown; a script that cannot be fetched throws a NetworkError.

ImportScripts overloads

ImportScripts(IEnumerable<object>)

WorkerGlobalScope.cs

Runs the scripts of urls synchronously, in order, in the realm of the worker (https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-importscripts).

public void ImportScripts(IEnumerable<object> urls)
Parameters
urls IEnumerable<object>
The URLs of the scripts (strings or TrustedScriptUrl objects), relative to the URL of the worker.
See also

ImportScripts(string[])

WorkerGlobalScope.cs

Runs the scripts of urls synchronously, in order, in the realm of the worker (https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-importscripts). The exceptions of the scripts are rethrown; a script that cannot be fetched throws a NetworkError.

public void ImportScripts(params string[] urls)
Parameters
urls string[]
The URLs of the scripts, relative to the URL of the worker.
Exceptions
TypeErrorException
The worker is a module worker.
DomException
A SyntaxError when a URL is invalid, or a NetworkError when a script cannot be fetched.