multipart/x-mixed-replace
resources
Certain actions cause the browsing context to navigate to a new resource. A user agent may provide various ways for the user to explicitly cause a browsing context to navigate, in addition to those defined in this specification.
For
example,
following
a
hyperlink
,
form
submission
,
and
the
window.open()
and
location.assign()
methods
can
all
cause
a
browsing
context
to
navigate.
A
resource
has
a
URL,
but
that
might
not
be
the
only
information
necessary
to
identify
it.
For
example,
a
form
submission
that
uses
HTTP
POST
would
also
have
the
HTTP
method
and
payload.
Similarly,
an
iframe
srcdoc
document
needs
to
know
the
data
it
is
to
use.
Navigation always involves source browsing context , which is the browsing context which was responsible for starting the navigation.
As explained in issue #1130 the use of a browsing context as source might not be the correct architecture.
To navigate a browsing context browsingContext to a resource resource , optionally with an exceptions enabled flag , the user agent must run these steps:
If resource is a URL , then set resource to a new request whose url is resource .
If resource is a request and this is a reload-triggered navigation , then set resource 's reload-navigation flag .
If the source browsing context is not allowed to navigate browsingContext , then:
If
the
exceptions
enabled
flag
is
set,
then
throw
a
"
SecurityError
"
DOMException
.
Otherwise, the user agent may instead offer to open resource in a new top-level browsing context or in the top-level browsing context of the source browsing context , at the user's option, in which case the user agent must navigate that designated top-level browsing context to resource as if the user had requested it independently.
Doing so, however, can be dangerous, as it means that the user is overriding the author's explicit request to sandbox the content.
If there is a preexisting attempt to navigate browsingContext , and the source browsing context is the same as browsingContext , and that attempt is currently running the unload a document algorithm, then return without affecting the preexisting attempt to navigate browsingContext .
If the prompt to unload algorithm is being run for the active document of browsingContext , then return without affecting the prompt to unload algorithm.
Let activeDocumentNavigationOrigin be the origin of the active document of browsingContext .
Let incumbentNavigationOrigin be the origin of the incumbent settings object , or if no script was involved, the origin of the node document of the element that initiated the navigation .
Cancel
any
preexisting
but
not
yet
mature
attempt
to
navigate
browsingContext
,
including
canceling
any
instances
of
the
fetch
algorithm
started
by
those
attempts.
If
one
of
those
attempts
has
already
created
and
initialized
a
new
Document
object
,
abort
that
Document
also.
(Navigation
attempts
that
have
matured
already
have
session
history
entries,
and
are
therefore
handled
during
the
update
the
session
history
with
the
new
page
algorithm,
later.)
Prompt to unload the active document of browsingContext . If the user refused to allow the document to be unloaded , then return.
If this instance of the navigation algorithm gets canceled while this step is running, the prompt to unload algorithm must nonetheless be run to completion.
Abort the active document of browsingContext .
If
browsingContext
is
a
child
browsing
context
,
then
put
it
in
the
delaying
load
events
mode
.
The
user
agent
must
take
this
child
browsing
context
out
of
the
delaying
load
events
mode
when
this
navigation
algorithm
later
matures
,
or
when
it
terminates
(whether
due
to
having
run
all
the
steps,
or
being
canceled,
or
being
aborted),
whichever
happens
first.
Let
navigationType
be
"
form-submission
"
if
the
navigation
algorithm
was
invoked
as
a
result
of
the
form
submission
algorithm
,
and
"
other
"
otherwise.
Let sandboxFlags be the result of determining sandboxing flags given browsingContext .
Return to whatever algorithm invoked the navigation steps and continue running these steps in parallel .
This is the step that attempts to obtain resource , if necessary. Jump to the first appropriate substep:
Run process a navigate response with null, resource , navigationType , the source browsing context , browsingContext , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin .
javascript
"
Queue a task , on the DOM manipulation task source and associated with the active document of browsingContext , to run these steps:
Let
response
be
the
result
of
executing
a
javascript:
URL
request
given
resource
,
the
source
browsing
context
,
and
browsingContext
.
Run process a navigate response with resource , response , navigationType , the source browsing context , browsingContext , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin .
So
for
example
a
javascript:
URL
in
an
href
attribute
of
an
a
element
would
only
be
evaluated
when
the
link
was
followed
,
while
such
a
URL
in
the
src
attribute
of
an
iframe
element
would
be
evaluated
in
the
context
of
the
iframe
's
nested
browsing
context
when
the
iframe
is
being
set
up.
Once
evaluated,
its
return
value
(if
it
was
a
string)
would
replace
that
browsing
context
's
active
document
,
thus
also
changing
the
corresponding
Window
object.
GET
`,
and
there
are
relevant
application
caches
that
are
identified
by
a
URL
with
the
same
origin
as
the
URL
in
question,
and
that
have
this
URL
as
one
of
their
entries,
excluding
entries
marked
as
foreign
,
and
whose
mode
is
fast
,
and
the
user
agent
is
not
in
a
mode
where
it
will
avoid
using
application
caches
Fetch resource from the most appropriate application cache of those that match.
For example, imagine an HTML page with an associated application cache displaying an image and a form, where the image is also used by several other application caches. If the user right-clicks on the image and chooses "View Image", then the user agent could decide to show the image from any of those caches, but it is likely that the most useful cache for the user would be the one that was used for the aforementioned HTML page. On the other hand, if the user submits the form, and the form does a POST submission, then the user agent will not use an application cache at all; the submission will be made to the network.
This still needs to be integrated with the Fetch standard. [FETCH]
Run process a navigate fetch given resource , the source browsing context , browsingContext , navigationType , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin .
javascript
"
nor
a
fetch
scheme
Run process a navigate URL scheme given resource 's url and browsingContext .
To process a navigate fetch , given a request request , two browsing contexts sourceBrowsingContext and browsingContext , a string navigationType , and two origins incumbentNavigationOrigin and activeDocumentNavigationOrigin , run these steps:
Let response be null.
Set
request
's
client
to
sourceBrowsingContext
's
active
document
's
relevant
settings
object
,
destination
to
"
document
",
mode
to
"
navigate
",
credentials
mode
to
"
include
",
use-URL-credentials
flag
,
redirect
mode
to
"
manual
",
and
replaces
client
id
to
browsingContext
's
active
document
's
relevant
settings
object
's
id
.
If browsingContext 's container is non-null and has a browsing context scope origin , then set request 's origin to that browsing context scope origin .
Let reservedEnvironment be null.
While true:
Let currentURL be response 's location URL , if response is not null, and request 's current URL otherwise.
If reservedEnvironment is not null and currentURL 's origin is not the same as reservedEnvironment 's creation URL 's origin , then:
Run the environment discarding steps for reservedEnvironment .
Set reservedEnvironment to null.
If reservedEnvironment is null, then set reservedEnvironment to a new environment whose id is a unique opaque string and target browsing context is browsingContext .
Set reservedEnvironment 's creation URL to currentURL .
The created environment's active service worker is set in the Handle Fetch algorithm during the fetch if the request URL matches a service worker registration. [SW]
Set request 's reserved client to reservedEnvironment .
If
the
Should
navigation
request
of
type
from
source
in
target
be
blocked
by
Content
Security
Policy?
algorithm
returns
"
Blocked
"
when
executed
upon
request
,
navigationType
,
sourceBrowsingContext
,
and
browsingContext
,
then
set
response
to
a
network
error
and
break
.
[CSP]
Otherwise:
If response is null, fetch request .
Otherwise, perform HTTP-redirect fetch using request and response .
Wait for the task on the networking task source to process response and set response to the result.
If response does not have a location URL or the location URL is not a URL whose scheme is an HTTP(S) scheme , then break .
Navigation
handles
redirects
manually
as
navigation
is
the
only
place
in
the
web
platform
that
cares
for
redirects
to
mailto:
URLs
and
such.
If response has a location URL that is failure, then set response to a network error .
Otherwise,
if
response
has
a
location
URL
that
is
a
URL
whose
scheme
is
"
blob
",
"
file
",
"
filesystem
",
or
"
javascript
",
then
set
response
to
a
network
error.
Otherwise, if response has a location URL that is a URL whose scheme is a fetch scheme , then run process a navigate fetch with a new request whose url is response 's location URL , sourceBrowsingContext , browsingContext , and navigationType , and return.
Otherwise, if response has a location URL that is a URL , run the process a navigate URL scheme given response 's location URL and browsingContext , and return.
Fallback
in
prefer-online
mode
:
If
response
was
not
fetched
from
an
application
cache
,
and
was
to
be
fetched
using
`
GET
`,
and
there
are
relevant
application
caches
that
are
identified
by
a
URL
with
the
same
origin
as
the
URL
in
question,
and
that
have
this
URL
as
one
of
their
entries,
excluding
entries
marked
as
foreign
,
and
whose
mode
is
prefer-online
,
and
the
user
didn't
cancel
the
navigation
attempt
during
the
earlier
step,
and
response
is
either
a
network
error
or
its
status
is
not
an
ok
status
,
then:
Let candidate be the response identified by the URL in question from the most appropriate application cache of those that match.
If candidate is not marked as foreign , then the user agent must discard the failed load and instead continue along these steps using candidate as response . The user agent may indicate to the user that the original page load failed, and that the page used was a previously cached response.
Fallback
for
fallback
entries
:
If
response
was
not
fetched
from
an
application
cache
,
and
was
to
be
fetched
using
`
GET
`,
and
its
URL
matches
the
fallback
namespace
of
one
or
more
relevant
application
caches
,
and
the
most
appropriate
application
cache
of
those
that
match
does
not
have
an
entry
in
its
online
safelist
that
has
the
same
origin
as
response
's
URL
and
that
is
a
prefix
match
for
response
's
URL,
and
the
user
didn't
cancel
the
navigation
attempt
during
the
earlier
step,
and
response
is
either
a
network
error
or
its
status
is
not
an
ok
status
,
then:
Let candidate be the fallback response specified for the fallback namespace in question. If multiple application caches match, the user agent must use the fallback of the most appropriate application cache of those that match.
If candidate is not marked as foreign , then the user agent must discard the failed load and instead continue along these steps using candidate as response . The document's URL , if appropriate, will still be the originally requested URL, not the fallback URL, but the user agent may indicate to the user that the original page load failed, that the page used was a fallback response, and what the URL of the fallback response actually is.
Run process a navigate response given request , response , navigationType , the source browsing context , browsingContext , incumbentNavigationOrigin , activeDocumentNavigationOrigin , and reservedEnvironment .
To process a navigate response , given null or a request request , a response response , a string navigationType , two browsing contexts source and browsingContext , a sandboxing flag set sandboxFlags , two origins incumbentNavigationOrigin and activeDocumentNavigationOrigin , and an optional environment reservedEnvironment , run these steps:
If
any
of
the
following
are
true,
then
display
the
inline
content
with
an
appropriate
error
shown
to
the
user
,
with
the
newly
created
Document
object's
origin
set
to
a
new
opaque
origin
,
run
the
environment
discarding
steps
for
reservedEnvironment
,
and
return.
response is a network error.
TODO:
Define
X-Frame-Options
processing
here
(tracked
as
issue
#1230
).
The
Should
navigation
response
to
navigation
request
of
type
from
source
in
target
be
blocked
by
Content
Security
Policy?
algorithm
returns
"
Blocked
"
when
executed
upon
request
,
response
,
navigationType
,
source
,
and
browsingContext
.
[CSP]
This is where the network errors defined and propagated by Fetch , such as DNS or TLS errors, end up being displayed to users. [FETCH]
If
response
's
status
is
204
or
205
,
then
return.
If
response
has
an
`
Content-Disposition
`
header
specifying
the
attachment
disposition
type,
then
run
the
allowed
to
download
algorithm
with
the
source
browsing
context
of
the
navigation
and
the
browsing
context
being
navigated
.
If
the
algorithm
returns
false,
return;
otherwise,
handle
response
as
a
download
and
return.
Let type be the computed type of response .
If the user agent has been configured to process resources of the given type using some mechanism other than rendering the content in a browsing context , then skip this step. Otherwise, if the type is one of the following types, jump to the appropriate entry in the following list, and process response as described there:
text/cache-manifest
"
text/css
"
text/plain
"
text/vtt
"
multipart/x-mixed-replace
"
An
explicitly
supported
XML
MIME
type
is
an
XML
MIME
type
for
which
the
user
agent
is
configured
to
use
an
external
application
to
render
the
content
(either
a
plugin
rendering
directly
in
browsingContext
,
or
a
separate
application),
or
one
for
which
the
user
agent
has
dedicated
processing
rules
(e.g.
a
Web
browser
with
a
built-in
Atom
feed
viewer
would
be
said
to
explicitly
support
the
application/atom+xml
MIME
type),
or
one
for
which
the
user
agent
has
a
dedicated
handler.
An explicitly supported JSON MIME type is a JSON MIME type for which the user agent is configured to use an external application to render the content (either a plugin rendering directly in browsingContext , or a separate application), or one for which the user agent has dedicated processing rules, or one for which the user agent has a dedicated handler.
Otherwise, the document's type is such that the resource will not affect browsingContext , e.g., because the resource is to be handed to an external application or because it is an unknown type that will be processed as a download . Process the resource appropriately .
To process a navigate URL scheme , given a URL url and browsing context browsingContext , run these steps:
If url is to be handled using a mechanism that does not affect browsingContext , e.g., because url 's scheme is handled externally, then proceed with that mechanism instead .
Otherwise, url is to be handled by displaying some sort of inline content, e.g., an error message because the specified scheme is not one of the supported protocols, or an inline prompt to allow the user to select a registered handler for the given scheme. Display the inline content .
In the case of a registered handler being used, navigate will be invoked with a new URL.
When
a
resource
is
handled
by
passing
its
URL
or
data
to
an
external
software
package
separate
from
the
user
agent
(e.g.
handing
a
mailto:
URL
to
a
mail
client,
or
a
Word
document
to
a
word
processor),
user
agents
should
attempt
to
mitigate
the
risk
that
this
is
an
attempt
to
exploit
the
target
software,
e.g.
by
prompting
the
user
to
confirm
that
the
source
browsing
context
's
active
document
's
origin
is
to
be
allowed
to
invoke
the
specified
software.
In
particular,
if
the
navigate
algorithm
was
invoked
when
source
browsing
context
's
WindowProxy
's
[[Window]]
value
does
not
have
transient
activation
,
the
user
agent
should
not
invoke
the
external
software
package
without
prior
user
confirmation.
For example, there could be a vulnerability in the target software's URL handler which a hostile page would attempt to exploit by tricking a user into clicking a link.
To
execute
a
javascript:
URL
request
,
given
a
request
request
and
two
browsing
contexts
source
and
browsingContext
,
run
these
steps:
If both of the following are true:
source 's active document 's origin is same origin with browsingContext 's active document 's origin .
As explained in issue #2591 this step does not work and presents a security issue.
The
Should
navigation
request
of
type
from
source
in
target
be
blocked
by
Content
Security
Policy?
algorithm
returns
"
Allowed
"
when
executed
upon
request
,
"
other
",
source
,
and
browsingContext
.
[CSP]
then:
Let urlString be the result of running the URL serializer on request 's url .
Let
encodedScriptSource
be
the
result
of
removing
the
leading
"
javascript:
"
from
urlString
.
Let scriptSource be the UTF-8 decoding of the string percent decoding of encodedScriptSource .
Append browsingContext 's active document 's URL to request 's URL list .
Let settings be browsingContext 's active document 's relevant settings object .
Let baseURL be settings 's API base URL .
Let script be the result of creating a classic script given scriptSource , settings , baseURL , and the default classic script fetch options .
Let evaluationStatus be the result of running the classic script script .
Let result be undefined if evaluationStatus is an abrupt completion or evaluationStatus .[[Value]] is empty, or evaluationStatus .[[Value]] otherwise.
If
Type
(
result
)
is
String,
then
set
response
to
a
response
whose
header
list
consists
of
`
Content-Type
`/`
text/html
`
and
`
Referrer-Policy
`/
settings
's
referrer
policy
,
whose
body
is
result
,
and
whose
HTTPS
state
is
settings
's
HTTPS
state
.
The exact conversion between the string result and the bytes that comprise a response body is not yet specified, pending further investigation into user agent behavior. See issue #1129 .
Return response .
In
addition
to
the
specific
issues
linked
above,
javascript:
URLs
have
a
dedicated
label
on
the
issue
tracker
documenting
various
problems
with
their
specification.
Some
of
the
sections
below,
to
which
the
above
algorithm
defers
in
certain
cases,
use
the
following
steps
to
create
and
initialize
a
Document
object
,
given
a
type
type
,
content
type
contentType
,
a
request
request
,
a
response
response
,
a
browsing
context
browsingContext
,
a
sandboxing
flag
set
sandboxFlags
,
two
origins
incumbentNavigationOrigin
,
activeDocumentNavigationOrigin
,
and
an
optional
environment
reservedEnvironment
:
Let finalSandboxFlags be the union of sandboxFlags and response 's forced sandboxing flag set .
Let origin be the result of determining the origin given browsingContext , request's url , finalSandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin .
Let featurePolicy be the result of creating a feature policy from a response given browsingContext , origin , and response . [FEATUREPOLICY]
The
creating
a
feature
policy
from
a
response
algorithm
makes
use
of
origin
.
If
document.domain
has
been
used
for
the
browsingContext
container
document
,
then
its
origin
cannot
be
same
origin-domain
with
>origin
,
because
these
steps
run
before
the
document
is
created,
so
it
cannot
itself
yet
have
used
document.domain
.
Note
that
this
means
that
Feature
Policy
checks
are
less
permissive
compared
to
doing
a
same
origin
check
instead.
See below for some examples of this in action.
If
browsingContext
's
only
entry
in
its
session
history
is
the
about:blank
Document
that
was
added
when
browsingContext
was
created
,
and
navigation
is
occurring
with
replacement
enabled
,
and
that
Document
has
the
same
origin
as
origin
,
then
do
nothing.
Otherwise:
Let agent be the result of obtaining a similar-origin window agent given origin and browsingContext 's group .
Let
realm
execution
context
be
the
result
of
creating
a
new
JavaScript
realm
with
given
agent
and
the
following
customizations:
For
the
global
object,
create
a
new
Window
object.
For
the
global
this
binding,
use
browsingContext
's
WindowProxy
object.
Let topLevelOrigin be origin if browsingContext is top-level browsing context , otherwise let topLevelOrigin be browsingContext 's top-level browsing context 's active document 's origin .
Set up a window environment settings object with realm execution context , topLevelOrigin , and reservedEnvironment , if present.
Let
document
be
a
new
Document
,
whose
type
is
type
,
content
type
is
contentType
,
origin
is
origin
,
feature
policy
is
featurePolicy
,
and
active
sandboxing
flag
set
is
finalSandboxFlags
.
If request is non-null, then set document 's URL to request 's current URL .
Set document 's HTTPS state to the HTTPS state of response .
Set
document
's
referrer
policy
to
the
result
of
parsing
the
`
Referrer-Policy
`
header
of
response
.
[REFERRERPOLICY]
Initialize
a
Document
's
CSP
list
given
document
,
response
,
and
request
.
[CSP]
If request is non-null, then set document 's referrer to the serialization of request 's referrer , if request 's referrer is a URL record , and the empty string otherwise.
Per
Fetch
a
request
's
referrer
will
be
either
a
URL
record
or
"
no-referrer
"
at
this
point.
If
response
has
a
`
Refresh
`
header,
then:
Let value be the isomorphic decoding of the value of the header.
Run the shared declarative refresh steps with document and value .
We
do
not
currently
have
a
spec
for
how
to
handle
multiple
`
Refresh
`
headers.
This
is
tracked
as
issue
#2900
.
Return document .
In
this
example,
the
child
document
is
not
allowed
to
use
PaymentRequest
,
despite
being
same
origin-domain
at
the
time
the
child
document
tries
to
use
it.
At
the
time
the
child
document
is
initialized,
only
the
parent
document
has
set
document.domain
,
and
the
child
document
has
not.
<!-- https://foo.example.com/a.html -->
<!doctype html>
<script>
document.domain = 'example.com';
</script>
<iframe
src=b.html></iframe>
<!-- https://bar.example.com/b.html -->
<!doctype html>
<script>
document.domain = 'example.com'; // This happens after the document is initialized
new PaymentRequest(…); // Not allowed to use
</script>
In
this
example,
the
child
document
is
allowed
to
use
PaymentRequest
,
despite
not
being
same
origin-domain
at
the
time
the
child
document
tries
to
use
it.
At
the
time
the
child
document
is
initialized,
none
of
the
documents
have
set
document.domain
yet
so
same
origin-domain
falls
back
to
a
normal
same
origin
check.
<!-- https://example.com/a.html -->
<!doctype html>
<iframe src=b.html></iframe>
<!-- The child document is now initialized, before the script below is run. -->
<script>
document.domain = 'example.com';
</script>
<!-- https://example.com/b.html -->
<!doctype html>
<script>
new PaymentRequest(…); // Allowed to use
</script>
Some
of
the
sections
below,
to
which
the
above
algorithm
defers
in
certain
cases,
require
the
user
agent
to
update
the
session
history
with
the
new
page
.
When
a
user
agent
is
required
to
do
this,
it
must
queue
a
task
on
the
networking
task
source
,
associated
with
the
Document
object
of
the
current
entry
(not
the
new
one),
to
run
the
following
steps:
Unload
the
Document
object
of
the
current
entry
.
If this instance of the navigation algorithm is canceled while this step is running the unload a document algorithm, then the unload a document algorithm must be allowed to run to completion, but this instance of the navigation algorithm must not run beyond this step. (In particular, for instance, the cancelation of this algorithm does not abort any event dispatch or script execution occurring as part of unloading the document or its descendants.)
Replace
the
Document
of
the
entry
being
updated,
and
any
other
entries
that
referenced
the
same
document
as
that
entry,
with
the
new
Document
.
Traverse the history to the new entry.
Replace
the
current
entry
with
a
new
entry
representing
the
new
resource
and
its
Document
object,
related
state,
and
the
default
scroll
restoration
mode
of
"
auto
".
Traverse the history to the new entry.
Remove all the entries in the browsing context 's session history after the current entry . If the current entry is the last entry in the session history, then no entries are removed.
This doesn't necessarily have to affect the user agent's user interface.
Append
a
new
entry
at
the
end
of
the
History
object
representing
the
new
resource
and
its
Document
object,
related
state,
and
the
default
scroll
restoration
mode
of
"
auto
".
Traverse the history to the new entry. If the navigation was initiated with replacement enabled , then the traversal must itself be initiated with replacement enabled .
The navigation algorithm has now matured .
Try
to
scroll
to
the
fragment
for
the
Document
.
To
try
to
scroll
to
the
fragment
for
a
Document
document
,
perform
the
following
steps
in
parallel
:
Wait for an implementation-defined amount of time. (This is intended to allow the user agent to optimize the user experience in the face of performance concerns.)
Queue a task on the networking task source to run these steps:
If document has no parser, or its parser has stopped parsing , or the user agent has reason to believe the user is no longer interested in scrolling to the fragment , then abort these steps.
Scroll to the fragment given in document 's URL . If this does not find an indicated part of the document , then try to scroll to the fragment for document .
When an HTML document is to be loaded in a browsing context , provided browsingContext , request , response , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin , the user agent must queue a task on the networking task source to:
Let
document
be
the
result
of
creating
and
initializing
a
Document
object
providing
"
html
",
"
text/html
",
request
,
response
,
browsingContext
,
sandboxFlags
,
incumbentNavigationOrigin
,
and
activeDocumentNavigationOrigin
.
Create an HTML parser and associate it with the document . Each task that the networking task source places on the task queue while fetching runs must then fill the parser's input byte stream with the fetched bytes and cause the HTML parser to perform the appropriate processing of the input stream.
The input byte stream converts bytes into characters for use in the tokenizer . This process relies, in part, on character encoding information found in the real Content-Type metadata of the resource; the computed type is not used for this purpose.
When
no
more
bytes
are
available,
the
user
agent
must
queue
a
task
on
the
networking
task
source
for
the
parser
to
process
the
implied
EOF
character,
which
eventually
causes
a
load
event
to
be
fired.
After
creating
the
Document
object,
but
before
any
script
execution,
certainly
before
the
parser
stops
,
the
user
agent
must
update
the
session
history
with
the
new
page
.
Application cache selection happens in the HTML parser .
When
faced
with
displaying
an
XML
file
inline,
provided
browsingContext
,
request
,
response
,
sandboxFlags
,
incumbentNavigationOrigin
,
and
activeDocumentNavigationOrigin
,
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
Document
object
providing
"
xml
",
type
,
request
,
response
,
browsingContext
,
sandboxFlags
,
incumbentNavigationOrigin
,
and
activeDocumentNavigationOrigin
.
It
must
also
create
and
a
corresponding
XML
parser
.
[XML]
[XMLNS]
[RFC7303]
[DOM]
At the time of writing, the XML specification community had not actually yet specified how XML and the DOM interact.
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.
If
the
document
element
,
as
parsed
according
to
XML
cited
above,
is
found
to
be
an
html
element
with
an
attribute
manifest
whose
value
is
not
the
empty
string,
then,
as
soon
as
the
element
is
inserted
into
the
document
,
the
user
agent
must
parse
the
value
of
that
attribute
relative
to
that
element's
node
document
,
and
if
that
is
successful,
must
apply
the
URL
serializer
algorithm
to
the
resulting
URL
record
with
the
exclude
fragment
flag
set
to
obtain
manifest
URL
,
and
then
run
the
application
cache
selection
algorithm
with
manifest
URL
as
the
manifest
URL,
passing
in
the
newly-created
Document
.
Otherwise,
if
the
attribute
is
absent,
its
value
is
the
empty
string,
or
parsing
its
value
fails,
then
as
soon
as
the
document
element
is
inserted
into
the
document
,
the
user
agent
must
run
the
application
cache
selection
algorithm
with
no
manifest,
and
passing
in
the
Document
.
Because
the
processing
of
the
manifest
attribute
happens
only
once
the
document
element
is
parsed,
any
URLs
referenced
by
processing
instructions
before
the
document
element
(such
as
<?xml-stylesheet?>
PIs)
will
be
fetched
from
the
network
and
cannot
be
cached.
Then,
with
the
newly
created
Document
,
the
user
agent
must
update
the
session
history
with
the
new
page
.
User
agents
may
do
this
before
the
complete
document
has
been
parsed
(thus
achieving
incremental
rendering
),
and
must
do
this
before
any
scripts
are
to
be
executed.
Error
messages
from
the
parse
process
(e.g.,
XML
namespace
well-formedness
errors)
may
be
reported
inline
by
mutating
the
Document
.
When a plain text document is to be loaded in a browsing context , provided browsingContext , request , response , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin , the user agent must queue a task on the networking task source to:
Let
document
be
the
result
of
creating
and
initialize
a
Document
object
providing
"
html
",
type
,
request
,
response
,
browsingContext
,
sandboxFlags
,
incumbentNavigationOrigin
,
and
activeDocumentNavigationOrigin
.
Create an HTML parser and associate it with the document . Act as if the tokenizer had emitted a start tag token with the tag name "pre" followed by a single U+000A LINE FEED (LF) character, and switch the HTML parser 's tokenizer to the PLAINTEXT state . Each task that the networking task source places on the task queue while fetching runs must then fill the parser's input byte stream with the fetched bytes and cause the HTML parser to perform the appropriate processing of the input stream.
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 ( type in the navigate algorithm).
The document's character encoding must be set to the character encoding used to decode the document.
Upon
creation
of
the
Document
object,
the
user
agent
must
run
the
application
cache
selection
algorithm
with
no
manifest,
and
passing
in
the
newly-created
Document
.
When
no
more
bytes
are
available,
the
user
agent
must
queue
a
task
on
the
networking
task
source
for
the
parser
to
process
the
implied
EOF
character,
which
eventually
causes
a
load
event
to
be
fired.
After
creating
the
Document
object,
but
potentially
before
the
page
has
finished
parsing,
the
user
agent
must
update
the
session
history
with
the
new
page
.
User
agents
may
add
content
to
the
head
element
of
the
Document
,
e.g.,
linking
to
a
style
sheet,
providing
script,
or
giving
the
document
a
title
.
In
particular,
if
the
user
agent
supports
the
Format=Flowed
feature
of
RFC
3676
then
the
user
agent
would
need
to
apply
extra
styling
to
cause
the
text
to
wrap
correctly
and
to
handle
the
quoting
feature.
This
could
be
performed
using,
e.g.,
a
CSS
extension.
multipart/x-mixed-replace
resources
When
a
resource
with
the
type
multipart/x-mixed-replace
is
to
be
loaded
in
a
browsing
context
,
the
user
agent
must
parse
the
resource
using
the
rules
for
multipart
types.
[RFC2046]
For
each
body
part
obtained
from
the
resource,
the
user
agent
must
run
process
a
navigate
response
using
the
new
body
part
and
the
same
browsing
context
,
with
replacement
enabled
if
a
previous
body
part
from
the
same
resource
resulted
in
a
creating
and
initializing
a
Document
object
,
and
otherwise
using
the
same
setup
as
the
navigate
attempt
that
caused
this
section
to
be
invoked
in
the
first
place.
For the purposes of algorithms processing these body parts as if they were complete stand-alone resources, the user agent must act as if there were no more bytes for those resources whenever the boundary following the body part is reached.
Thus,
load
events
(and
for
that
matter
unload
events)
do
fire
for
each
body
part
loaded.
When an image, video, or audio resource is to be loaded in a browsing context , provided browsingContext , request , response , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin , the user agent should:
Let
document
be
the
result
of
creating
and
initialize
a
Document
object
providing
"
html
",
type
,
request
,
response
,
browsingContext
,
sandboxFlags
,
incumbentNavigationOrigin
,
and
activeDocumentNavigationOrigin
.
Append
an
html
element
to
document
.
Append
an
element
host
element
for
the
media,
as
described
below,
to
the
body
element.
Set the appropriate attribute of the element host element , as described below, to the address of the image, video, or audio resource.
The element host element to create for the media is the element given in the table below in the second cell of the row whose first cell describes the media. The appropriate attribute to set is the one given by the third cell in that same row.
Type of media | Element for the media | Appropriate attribute |
---|---|---|
Image |
img
|
src
|
Video |
video
|
src
|
Audio |
audio
|
src
|
Then, the user agent must act as if it had stopped parsing .
Upon
creation
of
the
Document
object,
the
user
agent
must
run
the
application
cache
selection
algorithm
with
no
manifest,
and
passing
in
the
newly-created
Document
.
After
creating
the
Document
object,
but
potentially
before
the
page
has
finished
fully
loading,
the
user
agent
must
update
the
session
history
with
the
new
page
.
User
agents
may
add
content
to
the
head
element
of
the
Document
,
or
attributes
to
the
element
host
element
,
e.g.,
to
link
to
a
style
sheet,
to
provide
a
script,
to
give
the
document
a
title
,
or
to
make
the
media
autoplay
.
When a resource that requires an external resource to be rendered is to be loaded in a browsing context , provided browsingContext , request , response , sandboxFlags , incumbentNavigationOrigin , and activeDocumentNavigationOrigin , the user agent should:
Let
document
be
the
result
of
creating
and
initialize
a
Document
object
providing
"
html
",
type
,
request
,
response
,
browsingContext
,
sandboxFlags
,
incumbentNavigationOrigin
,
and
activeDocumentNavigationOrigin
.
Mark document as being a plugin document
Append
an
html
element
to
document
.
Set
the
src
attribute
of
the
embed
element
to
the
address
of
the
resource.
The
term
plugin
document
is
used
by
Content
Security
Policy
as
part
of
the
mechanism
that
ensures
iframe
s
can't
be
used
to
evade
plugin-types
directives.
[CSP]
Then, the user agent must act as if it had stopped parsing .
Upon
creation
of
the
Document
object,
the
user
agent
must
run
the
application
cache
selection
algorithm
with
no
manifest,
and
passing
in
the
newly-created
Document
.
After
creating
the
Document
object,
but
potentially
before
the
page
has
finished
fully
loading,
the
user
agent
must
update
the
session
history
with
the
new
page
.
User
agents
may
add
content
to
the
head
element
of
the
Document
,
or
attributes
to
the
embed
element,
e.g.
to
link
to
a
style
sheet
or
to
give
the
document
a
title
.
When
the
user
agent
is
to
display
a
user
agent
page
inline
in
a
browsing
context
,
the
user
agent
should
create
and
initialize
a
Document
object
providing
"
html
",
"
text/html
",
null,
null,
browsingContext
,
an
empty
set,
null,
and
null,
and
then
either
associate
that
Document
with
a
custom
rendering
that
is
not
rendered
using
the
normal
Document
rendering
rules,
or
mutate
that
Document
until
it
represents
the
content
the
user
agent
wants
to
render.
Once the page has been set up, the user agent must act as if it had stopped parsing .
Upon
creation
of
the
Document
object,
the
user
agent
must
run
the
application
cache
selection
algorithm
with
no
manifest,
passing
in
the
newly-created
Document
.
After
creating
the
Document
object,
but
potentially
before
the
page
has
been
completely
set
up,
the
user
agent
must
update
the
session
history
with
the
new
page
.
When a user agent is supposed to navigate to a fragment , optionally with replacement enabled , then the user agent must run the following steps:
If not with replacement enabled , then remove all the entries in the browsing context 's session history after the current entry . If the current entry is the last entry in the session history, then no entries are removed.
This doesn't necessarily have to affect the user agent's user interface.
Remove
any
tasks
queued
by
the
history
traversal
task
source
that
are
associated
with
any
Document
objects
in
the
top-level
browsing
context
's
document
family
.
Append
a
new
entry
at
the
end
of
the
History
object
representing
the
new
resource
and
its
Document
object,
related
state,
and
current
entry
's
scroll
restoration
mode
.
Its
URL
must
be
set
to
the
address
to
which
the
user
agent
was
navigating
.
The
title
must
be
left
unset.
Traverse the history to the new entry, with replacement enabled if this was invoked with replacement enabled , and with the non-blocking events flag set. This will scroll to the fragment given in what is now the document's URL .
If the scrolling fails because the relevant ID has not yet been parsed, then the original navigation algorithm will take care of the scrolling instead, as the last few steps of its update the session history with the new page algorithm.
When the user agent is required to scroll to the fragment and the indicated part of the document , if any, is being rendered , the user agent must either change the scrolling position of the document using the following algorithm, or perform some other action such that the indicated part of the document is brought to the user's attention. If there is no indicated part, or if the indicated part is not being rendered , then the user agent must do nothing. The aforementioned algorithm is as follows:
If
there
is
no
indicated
part
of
the
document
,
set
the
Document
's
target
element
to
null.
If the indicated part of the document is the top of the document, then:
Set
the
Document
's
target
element
to
null.
Scroll
to
the
beginning
of
the
document
for
the
Document
.
[CSSOMVIEW]
Otherwise:
Let target be element that is the indicated part of the document .
Set
the
Document
's
target
element
to
target
.
Scroll target into view , with behavior set to "auto", block set to "start", and inline set to "nearest". [CSSOMVIEW]
Run
the
focusing
steps
for
target
,
with
the
Document
's
viewport
as
the
fallback
target
.
Move the sequential focus navigation starting point to target .
The
indicated
part
of
the
document
is
the
one
that
the
fragment
,
if
any,
identifies.
The
semantics
of
the
fragment
in
terms
of
mapping
it
to
a
node
is
defined
by
the
specification
that
defines
the
MIME
type
used
by
the
Document
(for
example,
the
processing
of
fragments
for
XML
MIME
types
is
the
responsibility
of
RFC7303).
[RFC7303]
There
is
also
a
target
element
for
each
Document
,
which
is
used
in
defining
the
:target
pseudo-class
and
is
updated
by
the
above
algorithm.
It
is
initially
null.
For HTML documents (and HTML MIME types ), the following processing model must be followed to determine what the indicated part of the document is.
If fragment is the empty string, then the indicated part of the document is the top of the document; return.
If find a potential indicated element with fragment returns non-null, then the return value is the indicated part of the document ; return.
Let fragmentBytes be the result of string percent decoding fragment .
Let decodedFragment be the result of running UTF-8 decode without BOM on fragmentBytes .
If find a potential indicated element with decodedFragment returns non-null, then the return value is the indicated part of the document ; return.
If
decodedFragment
is
an
ASCII
case-insensitive
match
for
the
string
top
,
then
the
indicated
part
of
the
document
is
the
top
of
the
document;
return.
There is no indicated part of the document .
To find a potential indicated element given a string fragment , run these steps:
If there is an element in the document tree that has an ID equal to fragment , then return the first such element in tree order .
If
there
is
an
a
element
in
the
document
tree
that
has
a
name
attribute
whose
value
is
equal
to
fragment
,
then
return
the
first
such
element
in
tree
order
.
Return null.
The task source for the task mentioned in this section must be the DOM manipulation task source .
To traverse the history to a session history entry entry , optionally with replacement enabled , optionally with the non-blocking events flag set, and optionally with the history-navigation flag set:
This algorithm is not just invoked when explicitly going back or forwards in the session history — it is also invoked in other situations, for example when navigating a browsing context , as part of updating the session history with the new page .
If
entry
no
longer
holds
a
Document
object,
then:
If the history-navigation flag is set, then set request 's history-navigation flag .
Navigate the browsing context to request to perform an entry update of entry . The navigation must be done using the same source browsing context as was used the first time entry was created. (This can never happen with replacement enabled .)
The
"
navigate
"
algorithm
reinvokes
this
"traverse"
algorithm
to
complete
the
traversal,
at
which
point
entry
holds
a
Document
object.
If the resource was obtained using a non-idempotent action, for example a POST form submission, or if the resource is no longer available, for example because the computer is now offline and the page wasn't cached, navigating to it again might not be possible. In this case, the navigation will result in a different page than previously; for example, it might be an error message explaining the problem or offering to resubmit the form.
Return.
If
the
current
entry
's
title
was
not
set
by
the
pushState()
or
replaceState()
methods,
then
set
its
title
to
the
value
returned
by
the
document.title
IDL
attribute.
If
appropriate,
update
the
current
entry
in
the
browsing
context
's
Document
object's
History
object
to
reflect
any
state
that
the
user
agent
wishes
to
persist.
The
entry
is
then
said
to
be
an
entry
with
persisted
user
state
.
If
entry
has
a
different
Document
object
than
the
current
entry
,
then
run
the
following
substeps:
Remove
any
tasks
queued
by
the
history
traversal
task
source
that
are
associated
with
any
Document
objects
in
the
top-level
browsing
context
's
document
family
.
If
the
origin
of
entry
's
Document
object
is
not
the
same
as
the
origin
of
the
current
entry
's
Document
object,
then
run
the
following
subsubsteps:
The
current
browsing
context
name
must
be
stored
with
all
the
entries
in
the
history
that
are
associated
with
Document
objects
with
the
same
origin
as
the
active
document
and
that
are
contiguous
with
the
current
entry
.
If the browsing context is a top-level browsing context , but not an auxiliary browsing context , then set the browsing context's name to the empty string.
Set
the
active
document
of
the
browsing
context
to
entry
's
Document
object.
If entry has a browsing context name , then run the following subsubsteps:
Set the browsing context's browsing context name to entry 's browsing context name .
Clear
any
browsing
context
names
of
all
entries
in
the
history
that
are
associated
with
Document
objects
with
the
same
origin
as
the
new
active
document
and
that
are
contiguous
with
entry
.
If
entry
's
Document
object
has
any
form
controls
whose
autofill
field
name
is
"
off
",
invoke
the
reset
algorithm
of
each
of
those
elements.
If
the
current
document
readiness
of
entry
's
Document
object
is
"
complete
",
then
queue
a
task
to
run
the
following
subsubsteps:
If
the
Document
's
page
showing
flag
is
true,
then
abort
these
steps.
Set
the
Document
's
page
showing
flag
to
true.
Run
any
session
history
document
visibility
change
steps
for
Document
that
are
defined
by
other
applicable
specifications
.
This is specifically intended for use by Page Visibility . [PAGEVIS]
Fire
an
event
named
pageshow
at
the
Document
object's
relevant
global
object
,
using
PageTransitionEvent
,
with
the
persisted
attribute
initialized
to
true,
and
legacy
target
override
flag
set.
If
entry
has
a
URL
whose
fragment
differs
from
that
of
the
current
entry
's
when
compared
in
a
case-sensitive
manner,
and
the
two
share
the
same
Document
object,
then
let
hash
changed
be
true,
and
let
old
URL
be
the
current
entry
's
URL
and
new
URL
be
entry
's
URL
.
Otherwise,
let
hash
changed
be
false.
If the traversal was initiated with replacement enabled , remove the entry immediately before the specified entry in the session history.
If entry is not an entry with persisted user state , but its URL 's fragment is non-null, then scroll to the fragment .
Set the current entry to entry .
Let targetRealm be the current Realm Record .
If entry has serialized state , then let state be StructuredDeserialize ( entry 's serialized state , targetRealm ). If this throws an exception, catch it, ignore the exception, and let state be null.
Otherwise, let state be null.
Set
history.state
to
state
.
Let
state
changed
be
true
if
entry
's
Document
object
has
a
latest
entry
,
and
that
entry
is
not
entry
;
otherwise
let
it
be
false.
Set
entry
's
Document
object's
latest
entry
to
entry
.
If the non-blocking events flag is not set, then run the following substeps immediately . Otherwise, the non-blocking events flag flag is set; queue a task to run the following substeps instead.
If
state
changed
is
true,
then
fire
an
event
named
popstate
at
the
Document
object's
relevant
global
object
,
using
PopStateEvent
,
with
the
state
attribute
initialized
to
state
.
If entry is an entry with persisted user state , then the user agent may restore persisted user state and update aspects of the document and its rendering.
If
hash
changed
is
true,
then
fire
an
event
named
hashchange
at
the
browsing
context
's
Window
object,
using
HashChangeEvent
,
with
the
oldURL
attribute
initialized
to
old
URL
and
the
newURL
attribute
initialized
to
new
URL
.
The task source for the tasks mentioned above is the DOM manipulation task source .
When the user agent is to restore persisted user state from a history entry, it must run the following steps immediately:
If
the
entry
has
a
scroll
restoration
mode
,
let
scrollRestoration
be
that.
Otherwise
let
scrollRestoration
be
"
auto
"
If
scrollRestoration
is
"
manual
",
then
the
user
agent
should
not
restore
the
scroll
position
for
the
Document
or
any
of
its
scrollable
regions,
with
the
exception
of
any
child
browsing
contexts
of
Document
's
browsing
context
whose
scroll
restoration
is
controlled
by
their
own
history
entry's
scroll
restoration
mode
,
otherwise,
it
may
do
so.
Optionally, update other aspects of the document and its rendering, for instance values of form fields, that the user agent had previously recorded.
This
can
even
include
updating
the
dir
attribute
of
textarea
elements
or
input
elements
whose
type
attribute
is
in
either
the
Text
state
or
the
Search
state,
if
the
persisted
state
includes
the
directionality
of
user
input
in
such
controls.
Not restoring the scroll position by user agent does not imply that the scroll position will be left at any particular value (e.g., (0,0)). The actual scroll position depends on the navigation type and the user agent's particular caching strategy. So web applications cannot assume any particular scroll position but rather are urged to set it to what they want it to be.
PopStateEvent
interface
[Exposed=Window,
Constructor(DOMString type, optional PopStateEventInit eventInitDict = {})]
interface PopStateEvent : Event {
readonly attribute any state;
};
dictionary PopStateEventInit : EventInit {
any state = null;
};
state
Returns
a
copy
of
the
information
that
was
provided
to
pushState()
or
replaceState()
.
The
state
attribute
must
return
the
value
it
was
initialized
to.
It
represents
the
context
information
for
the
event,
or
null,
if
the
state
represented
is
the
initial
state
of
the
Document
.
HashChangeEvent
interface
Support: hashchange Chrome for Android 80+ Chrome 5+ iOS Safari 4.0+ Firefox 3.6+ Safari 5+ Samsung Internet 4+ UC Browser for Android 12.12+ Edge 12+ IE 8+ Opera 10.6+ Opera Mini None Android Browser 2.2+
Source: caniuse.com
[Exposed=Window,
Constructor(DOMString type, optional HashChangeEventInit eventInitDict = {})]
interface HashChangeEvent : Event {
readonly attribute USVString oldURL;
readonly attribute USVString newURL;
};
dictionary HashChangeEventInit : EventInit {
USVString oldURL = "";
USVString newURL = "";
};
oldURL
Returns the URL of the session history entry that was previously current.
newURL
Returns the URL of the session history entry that is now current.
The
oldURL
attribute
must
return
the
value
it
was
initialized
to.
It
represents
context
information
for
the
event,
specifically
the
URL
of
the
session
history
entry
that
was
traversed
from.
The
newURL
attribute
must
return
the
value
it
was
initialized
to.
It
represents
context
information
for
the
event,
specifically
the
URL
of
the
session
history
entry
that
was
traversed
to.
PageTransitionEvent
interface
[Exposed=Window,
Constructor(DOMString type, optional PageTransitionEventInit eventInitDict = {})]
interface PageTransitionEvent : Event {
readonly attribute boolean persisted;
};
dictionary PageTransitionEventInit : EventInit {
boolean persisted = false;
};
persisted
For
the
pageshow
event,
returns
false
if
the
page
is
newly
being
loaded
(and
the
load
event
will
fire).
Otherwise,
returns
true.
For
the
pagehide
event,
returns
false
if
the
page
is
going
away
for
the
last
time.
Otherwise,
returns
true,
meaning
that
(if
nothing
conspires
to
make
the
page
unsalvageable)
the
page
might
be
reused
if
the
user
navigates
back
to
this
page.
Things that can cause the page to be unsalvageable include:
beforeunload
events
unload
events
iframe
s
that
are
not
salvageable
WebSocket
objects
Document
The
persisted
attribute
must
return
the
value
it
was
initialized
to.
It
represents
the
context
information
for
the
event.
A
Document
has
a
salvageable
state,
which
must
initially
be
true,
a
fired
unload
flag,
which
must
initially
be
false,
and
a
page
showing
flag,
which
must
initially
be
false.
The
page
showing
flag
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).
Event loops have a termination nesting level counter, which must initially be 0.
To
prompt
to
unload
,
given
a
Document
object
document
and
optionally
a
recursiveFlag
,
run
these
steps:
Increase the event loop 's termination nesting level by 1.
Increase the document 's ignore-opens-during-unload counter by 1.
Let
event
be
the
result
of
creating
an
event
using
BeforeUnloadEvent
.
Initialize
event
's
type
attribute
to
beforeunload
and
its
cancelable
attribute
true.
Dispatch : Dispatch event at document 's relevant global object .
Decrease the event loop 's termination nesting level by 1.
If any event listeners were triggered by the earlier dispatch step, then set document 's salvageable state to false.
If
document
's
active
sandboxing
flag
set
does
not
have
its
sandboxed
modals
flag
set,
and
the
returnValue
attribute
of
the
event
object
is
not
the
empty
string,
or
if
the
event
was
canceled,
then
the
user
agent
may
ask
the
user
to
confirm
that
they
wish
to
unload
the
document.
The
message
shown
to
the
user
is
not
customizable,
but
instead
determined
by
the
user
agent.
In
particular,
the
actual
value
of
the
returnValue
attribute
is
ignored.
The user agent is encouraged to avoid asking the user for confirmation if it judges that doing so would be annoying, deceptive, or pointless. A simple heuristic might be that if the user has not interacted with the document, the user agent would not ask for confirmation before unloading it.
If the user agent asks the user for confirmation, it must pause while waiting for the user's response.
If the user did not confirm the page navigation, then the user agent refused to allow the document to be unloaded .
If the recursiveFlag is not set, then:
Let descendants be the list of the descendant browsing contexts of document .
For each browsingContext in descendants :
Prompt to unload browsingContext 's active document with the recursiveFlag set. If the user refused to allow the document to be unloaded , then the user implicitly also refused to allow document to be unloaded ; break .
If the salvageable state of browsingContext 's active document is false, then set the salvageable state of document to false.
Decrease the document 's ignore-opens-during-unload counter by 1.
To
unload
a
Document
document
,
optionally
given
a
recursiveFlag
:
Increase the event loop 's termination nesting level by one.
Increase document 's ignore-opens-during-unload counter by one.
If
document
's
page
showing
flag
is
false,
then
jump
to
the
step
labeled
unload
event
below
(i.e.
skip
firing
the
pagehide
event
and
don't
rerun
the
unloading
document
visibility
change
steps
).
Set document 's page showing flag to false.
Fire
an
event
named
pagehide
at
document
's
relevant
global
object
,
using
PageTransitionEvent
,
with
the
persisted
attribute
initialized
to
true
if
document
's
salvageable
state
is
true,
and
false
otherwise,
and
legacy
target
override
flag
set.
Run any unloading document visibility change steps for document that are defined by other applicable specifications .
This is specifically intended for use by Page Visibility . [PAGEVIS]
Unload
event
:
If
document
's
fired
unload
flag
is
false,
then
fire
an
event
named
unload
at
document
's
relevant
global
object
,
with
legacy
target
override
flag
set.
Decrease the event loop 's termination nesting level by one.
If any event listeners were triggered by the earlier unload event step, then set document 's salvageable state to false and set document 's fired unload flag to true.
Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications .
If the recursiveFlag is not set, then:
Let descendants be the list of the descendant browsing contexts of document .
For each browsingContext in descendants :
Unload the active document of browsingContext with the recursiveFlag set.
If the salvageable state of the active document of browsingContext is false, then set the salvageable state of document to false also.
If document 's salvageable state is false, then discard document .
Decrease document 's ignore-opens-during-unload counter by one.
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
set
document
's
salvageable
state
to
false.
If document 's salvageable state is false, then:
For
each
EventSource
object
eventSource
whose
relevant
global
object
is
equal
to
window
,
forcibly
close
eventSource
.
Empty window 's list of active timers .
BeforeUnloadEvent
interface
[Exposed=Window]
interface BeforeUnloadEvent : Event {
attribute DOMString returnValue;
};
There
are
no
BeforeUnloadEvent
-specific
initialization
methods.
The
BeforeUnloadEvent
interface
is
a
legacy
interface
which
allows
prompting
to
unload
to
be
controlled
not
only
by
canceling
the
event,
but
by
setting
the
returnValue
attribute
to
a
value
besides
the
empty
string.
Authors
should
use
the
preventDefault()
method,
or
other
means
of
canceling
events,
instead
of
using
returnValue
.
The
returnValue
attribute
controls
the
process
of
prompting
to
unload
.
When
the
event
is
created,
the
attribute
must
be
set
to
the
empty
string.
On
getting,
it
must
return
the
last
value
it
was
set
to.
On
setting,
the
attribute
must
be
set
to
the
new
value.
This
attribute
is
a
DOMString
only
for
historical
reasons.
Any
value
besides
the
empty
string
will
be
treated
as
a
request
to
ask
the
user
for
confirmation.
To
abort
a
Document
document
:
Abort
the
active
documents
of
every
child
browsing
context
.
If
this
results
in
any
of
those
Document
objects
having
their
salvageable
state
set
to
false,
then
set
document
's
salvageable
state
to
false
also.
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 set document 's salvageable state to false.
If document has an active parser , then:
Set document 's active parser was aborted to true.
Set document 's salvageable state to false.
User
agents
may
allow
users
to
explicitly
invoke
the
abort
a
document
algorithm
for
a
Document
.
If
the
user
does
so,
then,
if
that
Document
is
an
active
document
,
the
user
agent
should
queue
a
task
to
fire
an
event
named
abort
at
that
Document
object's
relevant
global
object
before
invoking
the
abort
algorithm.
To
stop
document
loading
given
a
Document
object
document
,
run
these
steps:
If document is not an active document , then return.
Let browsingContext be document 's browsing context .
If there is an existing attempt to navigate browsingContext and that attempt is not currently running the unload a document algorithm, then cancel that navigation .
Abort document .