Living Standard — Last Updated 29 June 2025
WindowOrWorkerGlobalScope
mixinVarious mechanisms can cause author-provided executable code to run in the context of a document. These mechanisms include, but are probably not limited to:
script
elements.javascript:
URLs.addEventListener()
, by explicit event handler content attributes, by
event handler IDL attributes, or otherwise.JavaScript defines the concept of an agent. This section gives the mapping of that language-level concept on to the web platform.
Conceptually, the agent concept is an architecture-independent, idealized "thread" in which JavaScript code runs. Such code can involve multiple globals/realms that can synchronously access each other, and thus needs to run in a single execution thread.
Two Window
objects having the same agent does not indicate
they can directly access all objects created in each other's realms. They would have to be
same origin-domain; see IsPlatformObjectSameOrigin.
The following types of agents exist on the web platform:
Contains various Window
objects which can potentially reach each other, either
directly or by using document.domain
.
If the encompassing agent cluster's is origin-keyed is true, then
all the Window
objects will be same origin, can reach each other
directly, and document.domain
will no-op.
Two Window
objects that are same origin can be in
different similar-origin window agents, for
instance if they are each in their own browsing context group.
Contains a single DedicatedWorkerGlobalScope
.
Contains a single SharedWorkerGlobalScope
.
Contains a single ServiceWorkerGlobalScope
.
Contains a single WorkletGlobalScope
object.
Although a given worklet can have multiple realms, each such realm needs its own agent, as each realm can be executing code independently and at the same time as the others.
Only shared and dedicated worker agents allow the use of JavaScript Atomics
APIs to
potentially block.
To create an agent, given a boolean canBlock:
Let signifier be a new unique internal value.
Let candidateExecution be a new candidate execution.
Let agent be a new agent whose [[CanBlock]] is canBlock, [[Signifier]] is signifier, [[CandidateExecution]] is candidateExecution, and [[IsLockFree1]], [[IsLockFree2]], and [[LittleEndian]] are set at the implementation's discretion.
Set agent's event loop to a new event loop.
Return agent.
For a realm realm, the agent whose [[Signifier]] is realm.[[AgentSignifier]] is the realm's agent.
The relevant agent for a platform object platformObject is platformObject's relevant realm's agent.
The agent equivalent of the current realm is the surrounding agent.
JavaScript also defines the concept of an agent cluster, which this standard maps to the web platform by placing agents appropriately when they are created using the obtain a similar-origin window agent or obtain a worker/worklet agent algorithms.
The agent cluster concept is crucial for defining the JavaScript memory model, and
in particular among which agents the backing data of
SharedArrayBuffer
objects can be shared.
Conceptually, the agent cluster concept is an architecture-independent, idealized "process boundary" that groups together multiple "threads" (agents). The agent clusters defined by the specification are generally more restrictive than the actual process boundaries implemented in user agents. By enforcing these idealized divisions at the specification level, we ensure that web developers see interoperable behavior with regard to shared memory, even in the face of varying and changing user agent process models.
An agent cluster has an associated cross-origin isolation mode, which is a
cross-origin isolation mode. It is initially "none
".
An agent cluster has an associated is origin-keyed (a boolean), which is initially false.
The following defines the allocation of the agent clusters of similar-origin window agents.
An agent cluster key is a site or tuple origin. Without web developer action to achieve origin-keyed agent clusters, it will be a site.
An equivalent formulation is that an agent cluster key can be a scheme-and-host or an origin.
To obtain a similar-origin window agent, given an origin origin, a browsing context group group, and a boolean requestsOAC, run these steps:
Let site be the result of obtaining a site with origin.
Let key be site.
If group's cross-origin isolation
mode is not "none
", then set
key to origin.
Otherwise, if group's historical agent cluster key map[origin] exists, then set key to group's historical agent cluster key map[origin].
Otherwise:
If requestsOAC is true, then set key to origin.
Set group's historical agent cluster key map[origin] to key.
If group's agent cluster map[key] does not exist, then:
Let agentCluster be a new agent cluster.
Set agentCluster's cross-origin isolation mode to group's cross-origin isolation mode.
If key is an origin:
Assert: key is origin.
Set agentCluster's is origin-keyed to true.
Add the result of creating an agent, given false, to agentCluster.
Set group's agent cluster map[key] to agentCluster.
Return the single similar-origin window agent contained in group's agent cluster map[key].
This means that there is only one similar-origin window agent per browsing context agent cluster. (However, dedicated worker and worklet agents might be in the same cluster.)
The following defines the allocation of the agent clusters of all other types of agents.
To obtain a worker/worklet agent, given an environment settings object or null outside settings, a boolean isTopLevel, and a boolean canBlock, run these steps:
Let agentCluster be null.
If isTopLevel is true, then:
Set agentCluster to a new agent cluster.
Set agentCluster's is origin-keyed to true.
These workers can be considered to be origin-keyed. However, this is not
exposed through any APIs (in the way that originAgentCluster
exposes the origin-keyedness for
windows).
Otherwise:
Let agent be the result of creating an agent given canBlock.
Add agent to agentCluster.
Return agent.
To obtain a dedicated/shared worker agent, given an environment settings object outside settings and a boolean isShared, return the result of obtaining a worker/worklet agent given outside settings, isShared, and true.
To obtain a worklet agent, given an environment settings object outside settings, return the result of obtaining a worker/worklet agent given outside settings, false, and false.
To obtain a service worker agent, return the result of obtaining a worker/worklet agent given null, true, and false.
The JavaScript specification introduces the realm concept, representing a global environment in which script is run. Each realm comes with an implementation-defined global object; much of this specification is devoted to defining that global object and its properties.
For web specifications, it is often useful to associate values or algorithms with a
realm/global object pair. When the values are specific to a particular type of realm, they are
associated directly with the global object in question, e.g., in the definition of the
Window
or WorkerGlobalScope
interfaces. When the values have utility
across multiple realms, we use the environment settings object concept.
Finally, in some cases it is necessary to track associated values before a realm/global object/environment settings object even comes into existence (for example, during navigation). These values are tracked in the environment concept.
An environment is an object that identifies the settings of a current or potential execution environment (i.e., a navigation params's reserved environment or a request's reserved client). An environment has the following fields:
An opaque string that uniquely identifies this environment.
A URL that represents the location of the resource with which this environment is associated.
In the case of a Window
environment settings object,
this URL might be distinct from its global
object's associated
Document
's URL, due to
mechanisms such as history.pushState()
which modify
the latter.
Null or a URL that represents the creation URL of the "top-level" environment. It is null for workers and worklets.
A for now implementation-defined value, null, or an origin. For a "top-level" potential execution environment it is null (i.e., when there is no response yet); otherwise it is the "top-level" environment's origin. For a dedicated worker or worklet it is the top-level origin of its creator. For a shared or service worker it is an implementation-defined value.
This is distinct from the top-level creation URL's origin when sandboxing, workers, and worklets are involved.
Null or a target browsing context for a