uBlockOrigin / uBlock-issues

This is the community-maintained issue tracker for uBlock Origin
https://github.com/gorhill/uBlock
945 stars 81 forks source link

'XMLHttpRequest.prototype.getResponseHeader()' issue in scriptlet and redirect #2518

Open piquark6046 opened 1 year ago

piquark6046 commented 1 year ago

Prerequisites

I tried to reproduce the issue when...

Description

Screencast from 2023-03-01 14-13-33.webm

A specific URL where the issue occurs.

https://piquark6046.github.io/testpage/XMLResponseHeader/

Steps to Reproduce

The step to reproduce is attached in the video.

piquark6046.github.io##+js(no-xhr-if, adsbygoogle.js)
||pagead2.googlesyndication.com/pagead/js/adsbygoogle.js$redirect=googlesyndication_adsbygoogle.js
@@||pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

Expected behavior

Actual behavior

When a $redirect filter is applied:

When a scriptlet filter is applied:

uBO version

1.47.2

Browser name and version

Mozilla Firefox Developer Edition 111.0b7

Operating System and version

Ubuntu 22.10

piquark6046 commented 1 year ago

Related issues:

JobcenterTycoon commented 1 year ago

Similar: https://github.com/uBlockOrigin/uAssets/issues/16430#issuecomment-1406557590

gorhill commented 1 year ago

Probably because on Firefox xhr requests are redirected using data: URI.


Also, please transcribe here the filter to use for your repro case.

piquark6046 commented 1 year ago

Added into Steps to Reproduce.

piquark6046 commented 1 year ago

I think that uBO on a chromium-based web browser [^1] is also affected.

[^1]: Brave 1.48.171

gorhill commented 1 year ago

I get exceptions being raised. Probably should move your <script> tag just before </body>.

uBlock-user commented 1 year ago

All methods and property return empty data.

A redirect only loads a specific resource, nothing else, thats always been the case with any redirect and not limited to xhr only.

gorhill commented 1 year ago

I want to go through repro steps, but your test case has an issue, your script references elements in the DOM which may not be there yet. If you move your script tag at the end of the body, the repro case will work without throwing an exception.

piquark6046 commented 1 year ago

Fixed.

MasterKia commented 1 year ago

Similar (the site uses response.status as bait): https://github.com/uBlockOrigin/uAssets/issues/14204

        let src = '[Some URL]';
        const controller = new AbortController();
        const timeout = setTimeout(() => controller.abort(), 10_000);
        let response;
        try {
            response = await fetch(src, {signal: controller.signal});
        }
        if (response.status !== 200) {
            this.#showFail();
            return;
        }
MasterKia commented 1 year ago

Isn't the behavior shown in the this thread by design?

https://github.com/uBlockOrigin/uBlock-issues/wiki/Resources-Library#no-fetch-ifjs- & https://github.com/uBlockOrigin/uBlock-issues/wiki/Resources-Library#no-xhr-ifjs-:

returning a promise which always resolve to an empty response.


Anyway, AdGuard's fix: https://github.com/AdguardTeam/Scriptlets/commit/531ea12e1c5ddc7d26bd61cdc095a30894d0687e#diff-ff559a075c8491c9b6a0cdeea5aceee74950e68eb2423435ab3afaa87c4452ccR28

JobcenterTycoon commented 1 year ago

https://github.com/gorhill/uBlock/commit/418087de9c307f3480af6a46daad1f554e0c29ce

ghajini commented 1 year ago

@gorhill are you planning to support no-fetch-if to return actual response? this is required for case here https://github.com/uBlockOrigin/uAssets/issues/19295

firefox

piquark6046 commented 1 year ago

@ghajini https://github.com/uBlockOrigin/uBlock-issues/issues/2526 Did you mean this issue?

ghajini commented 1 year ago

yes for no-fetch-if

uBlock-user commented 1 year ago

What was done for no-xhr-if in https://github.com/gorhill/uBlock/commit/bf591d93fbc692b7ccd0dfe630ed1cb0e5a33cfd needs to be done for no-fetch-if.

gwarser commented 11 months ago

'expires'?

uBlock-user commented 11 months ago

'expires' was not added or is missing..

gorhill commented 11 months ago

Adding expires is too arbitrary, it's not always there. I would want to see many real cases before I start to consider throwing in there arbitrary headers.

JobcenterTycoon commented 10 months ago

@gorhill will the Resources-Library get a update? The latest features like length: are missing.

MasterKia commented 10 months ago

I can update the wiki in a week or so.

JobcenterTycoon commented 9 months ago

Still not updated