GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing html.spec.whatwg.org — HTML Standard
7.5 Document lifecycle7.5.1 Shared document creation infrastructureWhen loading a document using one of the below algorithms, we use the
following steps to create and initialize a
In this example, the child document is not allowed to use
In this example, the child document is allowed to use
To populate with
7.5.2 Loading HTML documentsTo load an HTML document, given navigation params navigationParams:
7.5.3 Loading XML documentsWhen faced with displaying an XML file inline, provided navigation params
navigationParams and a string type, user agents must follow the
requirements defined in XML and Namespaces in XML, XML Media
Types, DOM, and other relevant specifications to create and initialize a At the time of writing, the XML specification community had not actually yet specified how XML and the DOM interact. The first task that the networking task source
places on the task queue while fetching runs must process link headers
given document, navigationParams's response, and " The actual HTTP headers and other metadata, not the headers as mutated or implied by the algorithms given in this specification, are the ones that must be used when determining the character encoding according to the rules given in the above specifications. Once the character encoding is established, the document's character encoding must be set to that character encoding. Before any script execution occurs, the user agent must wait for scripts may run for the
newly-created document to be true for the newly-created Once parsing is complete, the user agent must set document's during-loading navigation ID for WebDriver BiDi to null. For HTML documents this is reset when parsing is complete, after firing the load event. Error messages from the parse process (e.g., XML namespace well-formedness errors) may be
reported inline by mutating the 7.5.4 Loading text documentsTo load a text document, given a navigation params navigationParams and a string type:
The rules for how to convert the bytes of the plain text document into actual characters, and the rules for actually rendering the text to the user, are defined by the specifications for the computed MIME type of the resource (i.e., type). 7.5.5 Loading
|
| Type of media | Element for the media | Appropriate attribute |
|---|---|---|
| Image | img
| src
|
| Video | video
| src
|
| Audio | audio
| src
|
Before any script execution occurs, the user agent must wait for scripts may run for the
newly-created document to be true for the Document.
When the user agent is to create a document to display a user
agent page or PDF viewer inline,
provided a navigable navigable, a navigation ID
navigationId, a NavigationTimingType navTimingType, and a
user navigation involvement userInvolvement, the user agent should:
Let origin be a new opaque origin.
Let coop be a new opener policy.
Let coopEnforcementResult be a new opener policy enforcement result with
Let navigationParams be a new navigation params with
iframe element referrer policyLet document be the result of creating and initializing a Document
object given "html", "text/html", and
navigationParams.
Either associate document with a custom rendering that is not rendered using
the normal Document rendering rules, or mutate document until it
represents the content the user agent wants to render.
Act as if the user agent had stopped parsing document.
This is done to avoid leaking information to the parent page about whether a
navigation has been blocked by CSP, or if the response was a network error. In the
case where the container is an iframe element, stopping
parsing causes the iframe load event steps to run.
Return document.
Because we ensure the resulting Document's origin is opaque, and the resulting Document cannot run
script with access to the DOM, the existence and properties of this Document are not
observable to web developer code. This means that most of the above values, e.g., the
text/html type, do not matter.
Similarly, most of the items in navigationParams don't have any observable effect,
besides preventing the Document-creation
algorithm from getting confused, and so are set to default values.
A Document has a completely loaded time (a time or null), which is
initially null.
A Document is considered completely loaded if its completely
loaded time is non-null.
To completely finish loading a Document document:
Assert: document's browsing context is non-null.
Set document's completely loaded time to the current time.
Let container be document's node navigable's container.
This will be null in the case where document is the initial about:blank Document in a
frame or iframe, since at the point of browsing context creation which calls this algorithm,
the container relationship has not yet been established. (That happens in a subsequent step of
create a new child navigable.)
The consequence of this is that the following steps do nothing, i.e., we do not fire an
asynchronous load event on the container element for such
cases. Instead, a synchronous load event is fired in a special
initial-insertion case when processing the
iframe attributes.
If container is an iframe element, then queue an element
task on the DOM manipulation task source given container to run
the iframe load event steps given container.
Otherwise, if container is non-null, then queue an element task on
the DOM manipulation task source given container to fire an event named load at
container.
A Document has a salvageable state, which must initially be
true, and a page showing boolean, which is initially false. The page
showing boolean is used to ensure that scripts receive pageshow and pagehide events
in a consistent manner (e.g., that they never receive two pagehide events in a row without an intervening pageshow, or vice versa).
A Document has a DOMHighResTimeStamp suspension time,
initially 0.
A Document has a list of suspended timer handles,
initially empty.
Event loops have a termination nesting level counter, which must initially be 0.
Document objects have an unload
counter, which is used to ignore certain operations while the below algorithms run.
Initially, the counter must be set to zero.
To unload a Document
oldDocument, given an optional Document newDocument:
Assert: this is running as part of a task queued on oldDocument's relevant agent's event loop.
Let unloadTimingInfo be a new document unload timing info.
If newDocument is not given, then set unloadTimingInfo to null.
In this case there is no new document that needs to know about how long it took oldDocument to unload.
Otherwise, if newDocument's event loop is not oldDocument's event loop, then the user agent may be unloading oldDocument in parallel. In that case, the user agent should set unloadTimingInfo to null.
In this case newDocument's loading is not impacted by how long it takes to unload oldDocument, so it would be meaningless to communicate that timing info.
Let intendToKeepInBfcache be true if the user agent intends to keep oldDocument alive in a session history entry, such that it can later be used for history traversal.
This must be false if oldDocument is not salvageable, or if there are any descendants of oldDocument which the user agent does not intend to keep alive in the same way (including due to their lack of salvageability).
Let eventLoop be oldDocument's relevant agent's event loop.
Increase eventLoop's termination nesting level by 1.
Increase oldDocument's unload counter by 1.
If intendToKeepInBfcache is false, then set oldDocument's salvageable state to false.
If oldDocument's page showing is true:
Set oldDocument's page showing to false.
Fire a page transition event named pagehide at oldDocument's relevant global
object with oldDocument's salvageable state.
Update the visibility state of oldDocument to
"hidden".
If unloadTimingInfo is not null, then set unloadTimingInfo's unload event start time to the current high resolution time given newDocument's relevant global object, coarsened given oldDocument's relevant settings object's cross-origin isolated capability.
If oldDocument's salvageable
state is false, then fire an event named unload at oldDocument's relevant global
object, with legacy target override flag set.
If unloadTimingInfo is not null, then set unloadTimingInfo's unload event end time to the current high resolution time given newDocument's relevant global object, coarsened given oldDocument's relevant settings object's cross-origin isolated capability.
Decrease eventLoop's termination nesting level by 1.
Set oldDocument's suspension time to the current high resolution time given document's relevant global object.
Set oldDocument's suspended timer handles to the result of getting the keys for the map of active timers.
Set oldDocument's has been scrolled by the user to false.
Run any unloading document cleanup steps for oldDocument that are defined by this specification and other applicable specifications.
If oldDocument's node navigable is a top-level traversable, build not restored reasons for a top-level traversable and its descendants given oldDocument's node navigable.
If oldDocument's salvageable state is false, then destroy oldDocument.
Decrease oldDocument's unload counter by 1.
If newDocument is given, newDocument's was created via cross-origin redirects is false, and newDocument's origin is the same as oldDocument's origin, then set newDocument's previous document unload timing to unloadTimingInfo.
To unload a document and its descendants, given a Document
document, an optional Document-or-null newDocument (default
null), an optional set of steps afterAllUnloads, and an optional set of steps
firePageSwapSteps:
Assert: this is running within document's node navigable's traversable navigable's session history traversal queue.
Let childNavigables be document's child navigables.
Let numberUnloaded be 0.
For each childNavigable of childNavigables in what order?, queue a global task on the navigation and traversal task source given childNavigable's active window to perform the following steps:
Let incrementUnloaded be an algorithm step which increments numberUnloaded.
Unload a document and its descendants given childNavigable's active document, null, and incrementUnloaded.
Wait until numberUnloaded equals childNavigable's size.
Queue a global task on the navigation and traversal task source given document's relevant global object to perform the following steps:
If firePageSwapSteps is given, then run firePageSwapSteps.
Unload document, passing along newDocument if it is not null.
If afterAllUnloads was given, then run it.
This specification defines the following unloading document cleanup steps.
Other specifications can define more. Given a Document document:
Let window be document's relevant global object.
For each WebSocket object webSocket whose relevant global
object is window, make disappear webSocket.
If this affected any WebSocket objects, then make document
unsalvageable given document and "websocket".
For each WebTransport object transport whose relevant global
object is window, run the context cleanup steps given
transport.
If document's salvageable state is false:
For each EventSource object eventSource whose relevant
global object is equal to window, forcibly close
eventSource.
Clear window's map of active timers.
It would be better if specification authors sent a pull request to add calls from here into their specifications directly, instead of using the unloading document cleanup steps hook, to ensure well-defined cross-specification call order. As of the time of this writing the following specifications are known to have unloading document cleanup steps, which will be run in an unspecified order: Fullscreen API, Web NFC, WebDriver BiDi, Compute Pressure, File API, Media Capture and Streams, Picture-in-Picture, Screen Orientation, Service Workers, WebLocks API, WebAudio API, WebRTC. [FULLSCREEN] [WEBNFC] [WEBDRIVERBIDI] [COMPUTEPRESSURE] [FILEAPI] [MEDIASTREAM] [PICTUREINPICTURE] [SCREENORIENTATION] [SW] [WEBLOCKS] [WEBAUDIO] [WEBRTC]
Issue #8906 tracks the work to make the order of these steps clear.
To destroy a
Document document:
Assert: this is running as part of a task queued on document's relevant agent's event loop.
Abort document.
Set document's salvageable state to false.
Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications.
Remove any tasks whose document is document from any task queue (without running those tasks).
Set document's browsing context to null.
Set document's node navigable's active session history entry's document state's document to null.
Remove document from the
owner set of each WorkerGlobalScope object whose set contains document.
For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope.
Even after destruction, the Document object itself might still be
accessible to script, in the case where we are destroying a child navigable.
To destroy a document and its descendants given a Document
document and an optional set of steps afterAllDestruction, perform the
following steps in parallel:
If document is not fully active:
Let reason be a string from user-agent specific blocking reasons. If none
apply, then let reason be "masked".
Make document unsalvageable given document and reason.
If document's node navigable is a top-level traversable, build not restored reasons for a top-level traversable and its descendants given document's node navigable.
Let childNavigables be document's child navigables.
Let numberDestroyed be 0.
For each childNavigable of childNavigables in what order?, queue a global task on the navigation and traversal task source given childNavigable's active window to perform the following steps:
Let incrementDestroyed be an algorithm step which increments numberDestroyed.
Destroy a document and its descendants given childNavigable's active document and incrementDestroyed.
Wait until numberDestroyed equals childNavigable's size.
Queue a global task on the navigation and traversal task source given document's relevant global object to perform the following steps:
Destroy document.
If afterAllDestruction was given, then run it.
To abort a Document document:
Assert: this is running as part of a task queued on document's relevant agent's event loop.
Cancel any instances of the fetch algorithm in the
context of document, discarding any tasks queued for them, and discarding any further data received from the
network for them. If this resulted in any instances of the fetch algorithm being canceled or any queued tasks or any network data getting
discarded, then make document unsalvageable given document and
"fetch".
If document's during-loading navigation ID for WebDriver BiDi is non-null:
Invoke WebDriver BiDi navigation aborted with document's
node navigable and a new WebDriver BiDi navigation status whose id is document's during-loading navigation ID for WebDriver BiDi,
status is "canceled", and url is document's URL.
Set document's during-loading navigation ID for WebDriver BiDi to null.
If document has an active parser:
Set document's active parser was aborted to true.
Make document unsalvageable given document and
"parser-aborted".
To abort a document and its descendants given a Document
document:
Assert: this is running as part of a task queued on document's relevant agent's event loop.
Let descendantNavigables be document's descendant navigables.
For each descendantNavigable of descendantNavigables in what order?, queue a global task on the navigation and traversal task source given descendantNavigable's active window to perform the following steps:
Abort descendantNavigable's active document.
If descendantNavigable's active document's salvageable is false, then set document's salvageable to false.
Abort document.
To stop loading a navigable navigable:
Let document be navigable's active document.
If document's unload counter is 0, and navigable's ongoing navigation is a navigation ID, then set the ongoing navigation for navigable to null.
This will have the effect of aborting any ongoing navigations of navigable, since at certain points during navigation, changes to the ongoing navigation will cause further work to be abandoned.
Abort a document and its descendants given document.
Through their user interface, user agents also
allow stopping traversals, i.e. cases where the ongoing navigation is "traversal". The above algorithm does not account for this. (On the other hand,
user agents do not allow window.stop() to stop traversals,
so the above algorithm is correct for that caller.) See issue #6905.