GlobalScope Class

A global object (https://html.spec.whatwg.org/multipage/webappapis.html#global-object): a Window, or the global object of a worker (WorkerGlobalScope). It implements the members of the WindowOrWorkerGlobalScope mixin (https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin), and the parts of its environment settings object the library needs (its event loop, its script engine, the report of the exceptions and of the unhandled promise rejections).

public abstract class GlobalScope : EventTarget
Inheritance
EventTarget GlobalScope

Properties

NameDescription
CrossOriginIsolatedhttps://html.spec.whatwg.org/multipage/webappapis.html#dom-crossoriginisolated
IndexedDBGets the entry point of IndexedDB (https://w3c.github.io/IndexedDB/#dom-windoworworkerglobalscope-indexeddb): the databases of the origin, stored by BrowsingContextOptions.IndexedDB.
IsSecureContexthttps://html.spec.whatwg.org/multipage/webappapis.html#dom-issecurecontext
Originhttps://html.spec.whatwg.org/multipage/webappapis.html#dom-origin
Performancehttps://w3c.github.io/hr-time/#the-performance-attribute
SchedulerGets the scheduler of the global object (https://wicg.github.io/scheduling-apis/#dom-windoworworkerglobalscope-scheduler), which posts prioritized tasks to its event loop.

CrossOriginIsolated

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

public abstract bool CrossOriginIsolated { get; }

Gets the entry point of IndexedDB (https://w3c.github.io/IndexedDB/#dom-windoworworkerglobalscope-indexeddb): the databases of the origin, stored by BrowsingContextOptions.IndexedDB.

public IdbFactory IndexedDB { get; }

IsSecureContext

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

public abstract bool IsSecureContext { get; }

Origin

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

public abstract string Origin { get; }

Performance

GlobalScope.cs

https://w3c.github.io/hr-time/#the-performance-attribute

public Performance Performance { get; }

Gets the scheduler of the global object (https://wicg.github.io/scheduling-apis/#dom-windoworworkerglobalscope-scheduler), which posts prioritized tasks to its event loop.

public Scheduler Scheduler { get; }

Methods

NameDescription
Atob(string)https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
Btoa(string)https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa
ClearInterval(int)https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-clearinterval
ClearTimeout(int)https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-cleartimeout
CreateImageBitmap(object?, ImageBitmapOptions?)Creates a bitmap from an image source (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap): an img element, a canvas element, a Blob of an encoded image, an ImageData or another ImageBitmap. The images are decoded by the rendering backend of the browsing context (BrowsingContextOptions.RenderingBackend): without backend, an image or a blob cannot be decoded.
CreateImageBitmap(object?, int, int, int, int, ImageBitmapOptions?)Creates a bitmap from a rectangle of an image source (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap): see GlobalScope.CreateImageBitmap. The parts of the rectangle outside of the image are transparent black; a negative width or height extends the rectangle to the left or to the top.
QueueMicrotask(Action)https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask
ReportError(object?)https://html.spec.whatwg.org/multipage/webappapis.html#dom-reporterror: reports an exception, as if it was thrown by a script and not caught (an ErrorEvent is fired at the global object).
ReportException(ScriptError)Reports an exception to this global object (https://html.spec.whatwg.org/multipage/webappapis.html#report-an-exception): fires an ErrorEvent at the global object, then, when the event is not canceled (e.g. by onerror returning true), gives the error to BrowsingContextOptions.UnhandledScriptError (the error of a dedicated worker is first propagated to its Worker object). An exception reported while an error is being reported (e.g. thrown by an error event listener) does not fire another event.
SetInterval(TimerHandler, int, object?[])https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval: runs handler every timeout milliseconds.
SetInterval(Action, int)Runs a .NET callback repeatedly (see GlobalScope.SetInterval).
SetTimeout(TimerHandler, int, object?[])https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout: runs handler once, from a task, after timeout milliseconds (measured with DomEventLoop.TimeProvider).
SetTimeout(Action, int)Runs a .NET callback once, after a delay (see GlobalScope.SetTimeout).
StructuredClone(object?, StructuredSerializeOptions?)Returns a structured clone of a value (https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone): the value is serialized and deserialized in the realm of the global object by the script engine (without script engine, only the .NET primitive values and the serializable platform objects can be cloned). The objects of the transfer list are transferred (detached) when there is a script engine.
TrackPromiseRejection(object, object?, PromiseRejectionOperation)The HostPromiseRejectionTracker implementation of the HTML Standard (https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation), called by the script engine when a promise of the realm of the global object is rejected without handler, or when a handler is added to such a promise. The unhandledrejection events are fired after the next microtask checkpoint, and the rejectionhandled events by a task.

Atob(string)

GlobalScope.cs

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

public string Atob(string data)

Btoa(string)

GlobalScope.cs

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

public string Btoa(string data)

ClearInterval(int)

GlobalScope.Timers.cs

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-clearinterval

public void ClearInterval(int id = 0)

ClearTimeout(int)

GlobalScope.Timers.cs

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-cleartimeout

public void ClearTimeout(int id = 0)

CreateImageBitmap overloads

CreateImageBitmap(object?, ImageBitmapOptions?)

ImageBitmapFactory.cs

Creates a bitmap from an image source (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap): an img element, a canvas element, a Blob of an encoded image, an ImageData or another ImageBitmap. The images are decoded by the rendering backend of the browsing context (BrowsingContextOptions.RenderingBackend): without backend, an image or a blob cannot be decoded.

public Task<ImageBitmap> CreateImageBitmap(object? image, ImageBitmapOptions? options = null)
Parameters
image object?
The image source.
options ImageBitmapOptions?
The orientation, the scaling and the color options.
Returns

Task<ImageBitmap> A task that completes with the bitmap (in a task of the event loop), or fails with an InvalidStateError when the source cannot be used or decoded.

See also

CreateImageBitmap(object?, int, int, int, int, ImageBitmapOptions?)

ImageBitmapFactory.cs

Creates a bitmap from a rectangle of an image source (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap): see GlobalScope.CreateImageBitmap. The parts of the rectangle outside of the image are transparent black; a negative width or height extends the rectangle to the left or to the top.

public Task<ImageBitmap> CreateImageBitmap(object? image, int sx, int sy, int sw, int sh, ImageBitmapOptions? options = null)

QueueMicrotask(Action)

GlobalScope.cs

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask

public void QueueMicrotask(Action callback)

ReportError(object?)

GlobalScope.cs

https://html.spec.whatwg.org/multipage/webappapis.html#dom-reporterror: reports an exception, as if it was thrown by a script and not caught (an ErrorEvent is fired at the global object).

public void ReportError(object? e)

Parameters

e object?
The exception: a value of the script engine, or a .NET exception (null is the value undefined).

See also

ReportException(ScriptError)

GlobalScope.cs

Reports an exception to this global object (https://html.spec.whatwg.org/multipage/webappapis.html#report-an-exception): fires an ErrorEvent at the global object, then, when the event is not canceled (e.g. by onerror returning true), gives the error to BrowsingContextOptions.UnhandledScriptError (the error of a dedicated worker is first propagated to its Worker object). An exception reported while an error is being reported (e.g. thrown by an error event listener) does not fire another event.

public bool ReportException(ScriptError error)

Parameters

error ScriptError
The information of the exception.

Returns

bool Whether the error was handled: the error event was canceled.

SetInterval overloads

SetInterval(TimerHandler, int, object?[])

GlobalScope.Timers.cs

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval: runs handler every timeout milliseconds.

public int SetInterval(TimerHandler handler, int timeout = 0, params object?[] arguments)
Parameters
handler TimerHandler
A callback, or the source text of a script, which only runs when the browsing context has a script engine.
timeout int
The interval in milliseconds.
arguments object?[]
The arguments of the callback.
Returns

int The identifier of the timer, for GlobalScope.ClearInterval.

See also

SetInterval(Action, int)

GlobalScope.Timers.cs

Runs a .NET callback repeatedly (see GlobalScope.SetInterval).

public int SetInterval(Action handler, int timeout = 0)
Parameters
handler Action
timeout int
Returns

int

SetTimeout overloads

SetTimeout(TimerHandler, int, object?[])

GlobalScope.Timers.cs

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout: runs handler once, from a task, after timeout milliseconds (measured with DomEventLoop.TimeProvider).

public int SetTimeout(TimerHandler handler, int timeout = 0, params object?[] arguments)
Parameters
handler TimerHandler
A callback, or the source text of a script, which only runs when the browsing context has a script engine.
timeout int
The delay in milliseconds.
arguments object?[]
The arguments of the callback.
Returns

int The identifier of the timer, for GlobalScope.ClearTimeout.

See also

SetTimeout(Action, int)

GlobalScope.Timers.cs

Runs a .NET callback once, after a delay (see GlobalScope.SetTimeout).

public int SetTimeout(Action handler, int timeout = 0)
Parameters
handler Action
timeout int
Returns

int

StructuredClone(object?, StructuredSerializeOptions?)

GlobalScope.cs

Returns a structured clone of a value (https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone): the value is serialized and deserialized in the realm of the global object by the script engine (without script engine, only the .NET primitive values and the serializable platform objects can be cloned). The objects of the transfer list are transferred (detached) when there is a script engine.

public object? StructuredClone(object? value, StructuredSerializeOptions? options = null)

Parameters

value object?
The value: a value of the script engine, a .NET primitive value or a serializable platform object, or null for undefined.
options StructuredSerializeOptions?
The options: the objects to transfer.

Returns

object? The clone of the value.

Exceptions

DomException
A DataCloneError when the value cannot be cloned, or when an object of the transfer list cannot be transferred.

See also

TrackPromiseRejection(object, object?, PromiseRejectionOperation)

GlobalScope.cs

The HostPromiseRejectionTracker implementation of the HTML Standard (https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation), called by the script engine when a promise of the realm of the global object is rejected without handler, or when a handler is added to such a promise. The unhandledrejection events are fired after the next microtask checkpoint, and the rejectionhandled events by a task.

public void TrackPromiseRejection(object promise, object? reason, PromiseRejectionOperation operation)

Parameters

promise object
The promise.
reason object?
The rejection reason of the promise (its [[PromiseResult]]).
operation PromiseRejectionOperation
The operation.