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

Fix sync xhr in Firefox #47

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open

Conversation

mnaoumov
Copy link

@mnaoumov mnaoumov commented Mar 1, 2016

Fixes #46

See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

> Note: Starting with Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 /
> SeaMonkey 2.8), Gecko no longer lets you use the withCredentials
> attribute when performing synchronous requests. Attempting to do so
> throws an NS_ERROR_DOM_INVALID_ACCESS_ERR exception.
@jpillora
Copy link
Owner

jpillora commented Mar 1, 2016

Thanks for the PR, though is sync+withCreds xhr allowed in other browsers?

@mnaoumov
Copy link
Author

mnaoumov commented Mar 1, 2016

@jpillora According to W3C spec it is not allowed https://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute

When set: throws an "InvalidAccessError" exception if the synchronous flag is set and the JavaScript global environment is a document environment.

In reality only Firefox enforces this rule so far

UPD: I think there is no need to support the functionality that is against the spec even if other browsers are not too strict to the spec yet. So I would merge my pull request without any doubts.

But of course you might consider to add browser detection to cover the bug

@garrylachman
Copy link

Same in chrome now...
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.Setting 'XMLHttpRequest.withCredentials' for synchronous requests is deprecated.

xhook.before is not working

@morsdyce
Copy link
Collaborator

morsdyce commented Mar 3, 2017

Hi There @mnaoumov

I've looked at this PR and could not get a failing test case to work.
In your current PR the provided test doesn't actually check anything.

I've modified the test to check that the request does finish and it passes even with a sync XHR.

Here is the code for that test:

it('sync XHR should not fail', function(done) {
      var xhr = new XMLHttpRequest();
      xhr.open('GET', '../example/example1.txt', false);
      xhr.onload = function() {
        expect(xhr.responseText).to.contain('the first text file');
        done();
      };

      xhr.send();
    });

Is this still a problem for you? Could you provide a small example where this isn't working?

Thanks!

@github-actions github-actions bot force-pushed the gh-pages branch 2 times, most recently from 0d383e5 to b68decc Compare August 19, 2022 14:11
@github-actions github-actions bot force-pushed the gh-pages branch 2 times, most recently from 6047ce7 to 07a4ac7 Compare August 28, 2023 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants