Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can fetches start during 7.8.12 Aborting a document load ? #1334

Open
natechapin opened this issue May 27, 2016 · 8 comments
Open

Can fetches start during 7.8.12 Aborting a document load ? #1334

natechapin opened this issue May 27, 2016 · 8 comments

Comments

@natechapin
Copy link

https://html.spec.whatwg.org/multipage/browsers.html#abort-a-document

What should happen if a fetch starts during the invocation of this algorithm? Suppose an XHR's onabort fires as a result of its cancellation and starts a new XHR. Should that XHR be allowed to start, or should it be blocked/cancelled? Currently there's at least some divergence: Firefox appears to block the fetch, but Chrome starts the fetch.

@annevk
Copy link
Member

annevk commented May 28, 2016

It seems the document is no longer an active document once it's being aborted? That might be enough reason not to be able to use Fetch from such a document.

@natechapin
Copy link
Author

I'm a little hazy on the spec definition of an "active" Document, but based on https://html.spec.whatwg.org/multipage/browsers.html#active-document ("At any time, one Document in each browsing context is designated the active document.") , I would have assumed that an aborted Document remains the active Document unless another Document explicitly becomes active. Have I misunderstood?

@annevk
Copy link
Member

annevk commented Jun 7, 2016

Probably not. E.g., looks like the document remains the same in the document.open() scenario, but also gets aborted halfway through.

Can you share a testcase? Since it's not clear to me how you can run JavaScript while abort a document is running.

@annevk
Copy link
Member

annevk commented Jun 7, 2016

Hmm, perhaps through the abort event? I wonder how that works for multiple nested documents. And how many user agents still fire that.

@natechapin
Copy link
Author

natechapin commented Jun 8, 2016

I was using the snippet below. Chrome shows an "In stop: true" in the console, while Firefox doesn't.

<script>
var requests = [];
var inStop = false;
function startRequest() {
  var x = new XMLHttpRequest();
  x.open("GET", location, true);
  x.onabort = startRequest;
  x.send(null);
  requests.push(x);
  console.log("In stop: " + inStop);
}

startRequest();
inStop = true;
window.stop();
inStop = false;
</script>

@annevk
Copy link
Member

annevk commented Jun 9, 2016

I'm not sure what is best here. @bzbarsky, care to chime in? Happy to define whatever...

@bzbarsky
Copy link
Contributor

bzbarsky commented Jun 9, 2016

I'm pretty sure the Gecko behavior is that we only dispatch the "abort" event when abort() is called on the XHR object. Some of these calls are internal, but I don't think any of them would be triggered by window.stop(). I'm pretty sure they would be triggered by actual navigation away from the document, but I'm not sure we do it at the same place as the spec "aborts" a document. Oh, and the load might be canceled before that by the equivalent of stop that happens when navigation fetch starts, which is way before the document is aborted iirc. But that load cancel doesn't fire the "abort" event in Gecko, afaict.

On the other hand, "readystatechange" events totally fire for all this stuff in Gecko, albeit async: the network load is canceled and it asynchronously propagates that information back to whatever is waiting for it. So if you change this testcase to use onreadystatechange, you do see multiple startRequest calls, but inStop is false during all of them.

On the general topic here, in an ideal world aborting a document would not run any script synchronously at all... At worst it would queue some tasks to do stuff that might try to run script and do fetches, but at that point we're not dealing with this weird reentry kind of situation or documents in some half-inconsistent state.

@ericf01
Copy link

ericf01 commented May 23, 2017

A full discussion of the issue, involving a work-around for Mozilla Firefox from @bzbarsky including his suggestion that it be posted in #1382, can be reviewed at https://bugzilla.mozilla.org/show_bug.cgi?id=1315741.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants