Class WorkerGlobalScope
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The WorkerGlobalScope interface of the Web Workers API is an interface representing the scope of any worker. Workers have no browsing context; this scope contains the information usually conveyed by Window objects — in this case event handlers, the console or the associated WorkerNavigator object. Each WorkerGlobalScope has its own event loop.
[Value("WorkerGlobalScope")]
public class WorkerGlobalScope : EventTarget, FontFaceSource, WindowOrWorkerGlobalScope
- Inheritance
-
WorkerGlobalScope
- Implements
- Derived
- Inherited Members
Remarks
This interface is usually specialized by each worker type: DedicatedWorkerGlobalScope for dedicated workers, SharedWorkerGlobalScope for shared workers, and ServiceWorkerGlobalScope for ServiceWorker. The self property returns the specialized scope for each context.
-Other global object interface: Window, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope
-Other Worker-related interfaces: Worker, WorkerLocation and WorkerNavigator
-Using web workers
Constructors
WorkerGlobalScope()
public WorkerGlobalScope()
Properties
Location
The read-only location property of the WorkerGlobalScope interface returns the WorkerLocation associated with the worker. It is a specific location object, mostly a subset of the Location for browsing scopes, but adapted to workers.
[Value("location")]
public WorkerLocation Location { get; }
Property Value
- WorkerLocation
A WorkerLocation object.
Remarks
Navigator
The navigator read-only property of the WorkerGlobalScope interface returns the WorkerNavigator associated with the worker. It is a specific navigator object, mostly a subset of the Navigator for browsing scopes, but adapted to workers.
[Value("navigator")]
public WorkerNavigator Navigator { get; }
Property Value
- WorkerNavigator
A WorkerNavigator object.
Remarks
Onerror
[Value("onerror")]
public OnErrorEventHandlerNonNull Onerror { get; set; }
Property Value
Onlanguagechange
[Value("onlanguagechange")]
public EventHandlerNonNull Onlanguagechange { get; set; }
Property Value
Onoffline
[Value("onoffline")]
public EventHandlerNonNull Onoffline { get; set; }
Property Value
Ononline
[Value("ononline")]
public EventHandlerNonNull Ononline { get; set; }
Property Value
Onrejectionhandled
[Value("onrejectionhandled")]
public EventHandlerNonNull Onrejectionhandled { get; set; }
Property Value
Onunhandledrejection
[Value("onunhandledrejection")]
public EventHandlerNonNull Onunhandledrejection { get; set; }
Property Value
Self
The self read-only property of the WorkerGlobalScope interface returns a reference to the WorkerGlobalScope itself. Most of the time it is a specific scope like DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, or ServiceWorkerGlobalScope.
[Value("self")]
public WorkerGlobalScope Self { get; }
Property Value
- WorkerGlobalScope
A global scope object (differs depending on the type of worker you are dealing with, as indicated above).
Remarks
Methods
ImportScripts(params Union95[])
WARNING
The parameters passed to this method represent the URLs of classic scripts to be imported into a worker.
APIs like this are known as injection sinks, and are potentially a vector for cross-site scripting (XSS) attacks.
[Value("importScripts")]
public GlobalObject.Undefined ImportScripts(params Union95[] urls)
Parameters
urlsUnion95[]
Returns
Remarks
You can mitigate this risk by having a Content Security Policy (CSP) that restricts the locations from which scripts can be loaded, and by always assigning TrustedScriptURL objects instead of strings and enforcing trusted types.
See Security considerations for more information.
The importScripts() method of the WorkerGlobalScope interface synchronously imports one or more scripts into the scope of a classic worker (a worker constructed from a classic script).
Note that the method cannot be used in module workers, which instead load dependencies using import statements.