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

Improve 'prevent-xhr' — multiple requests #347

Closed
AdamWr opened this issue Aug 1, 2023 · 1 comment
Closed

Improve 'prevent-xhr' — multiple requests #347

AdamWr opened this issue Aug 1, 2023 · 1 comment

Comments

@AdamWr
Copy link
Member

AdamWr commented Aug 1, 2023

Related to - #261, but a bit different.

Steps to reproduce

  1. Add this rule:
example.org#%#//scriptlet('prevent-xhr', '/advert')
  1. Go to - https://example.org/
  2. Run in console
const xhr_should_be_blocked = new XMLHttpRequest();
const xhr_should_not_blocked = new XMLHttpRequest();
xhr_should_be_blocked.open('GET', '/advert', true);
xhr_should_not_blocked.open('GET', '/test', true);
xhr_should_be_blocked.send(null);
xhr_should_not_blocked.send(null);

xhr_should_be_blocked.responseURL should returns 'https://example.org/advert', but it returns 'https://example.org/test'.

Screenshot

image

The problem is here:

responseURL: { value: responseURL || xhrData.url, writable: false },

xhrData.url is from second request.
We could add something like thisArg.url = xhrData.url, here:
} else if (matchRequestProps(source, propsToMatch, xhrData)) {
thisArg.shouldBePrevented = true;
}

and then use it in responseURL instead of xhrData.url.

@AdamWr
Copy link
Member Author

AdamWr commented Aug 1, 2023

Another issue is that xhr_should_not_blocked.getAllResponseHeaders() (same steps as in previous comment) throws error.
Uncaught TypeError: Cannot read properties of undefined (reading 'length')

Screenshot

image

@adguard-bot adguard-bot assigned slavaleleka and unassigned maximtop Aug 1, 2023
adguard pushed a commit that referenced this issue Aug 3, 2023
Squashed commit of the following:

commit 7de58b6
Author: Adam Wróblewski <adam@adguard.com>
Date:   Tue Aug 1 20:15:15 2023 +0200

    Fix issue with multiple requests in prevent-xhr
@slavaleleka slavaleleka added bug Something isn't working and removed Release: v1.9.62 labels Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants