Are HTTP requests always cancelled by all browsers if originator iframe is destroyed before it completes?

1.2k views Asked by At

On Chrome I have noticed that if I destroy an iframe before a request to submit a form inside it completes then the request is cancelled. This does not seem to happen in Firefox and IE.

Is this something which the spec recommends ? Do other browsers plan to do the same in future?

1

There are 1 answers

0
ellisbben On

"Do other browsers plan to do the same in the future?"

No clue, but the chain of specification that I show below ultimately relies on the fetch specification, which was motivated in part by service workers, which are supported by Chrome and Firefox, "In Development" for MS Edge, and "Under Consideration" for WebKit (as of 2017-01-17).

WHATWG's iframe section states:

When an iframe element is removed from a document, the user agent must discard the element's nested browsing context, if it is not null, and then set the element's nested browsing context to null.

NOTE This happens without any unload events firing (the nested browsing context and its Document are discarded, not unloaded).

WHATWG's browsers document's discard a Document section states:

When a browsing context is to discard a Document, the user agent must run the following steps:

Set the Document's salvageable state to false.

Run any unloading document cleanup steps for the Document that are defined by this specification and other applicable specifications.

Abort the Document. [emphasis added]

Remove any tasks associated with the Document in any task source, without running those tasks.

Discard all the child browsing contexts of the Document.

Lose the strong reference from the Document's browsing context to the Document.

The same document's section on aborting a document states:

If a Document is aborted, the user agent must run the following steps:

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 this Document's salvageable state to false also.

Cancel any instances of the fetch algorithm [emphasis added] in the context of this 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 the Document's salvageable state to false.

If the Document has an active parser, then abort that parser and set the Document's salvageable state to false.

Given that the "fetch algorithm" is the new-ish standards-ized way in which a browser makes any HTTP request, I interpret the cancellation of any incomplete requests made by a removed iframe as consistent with the above sections.

Cf. the fetch spec if you haven't had enough yet. :)

References again

The iframe element

Discard a Document

Abort a Document

Fetch spec