Skip to content

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

Description

@piquark6046

Prerequisites

  • I verified that this is not a filter list issue. Report any issues with filter lists or broken website functionality in the uAssets issue tracker.
  • This is not a support issue or a question. For support, questions, or help, visit /r/uBlockOrigin.
  • I performed a cursory search of the issue tracker to avoid opening a duplicate issue.
  • The issue is not present after disabling uBO in the browser.
  • I checked the documentation to understand that the issue I am reporting is not normal behavior.

I tried to reproduce the issue when...

  • uBO is the only extension.
  • uBO uses default lists and settings.
  • using a new, unmodified browser profile.

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

  • XMLHttpRequest.prototype.status returns 200.
  • XMLHttpRequest.prototype.getResponseHeader('content-length') returns a digit number.
  • XMLHttpRequest.prototype.getResponseHeader('expires') returns a date and time.
  • XMLHttpRequest.prototype.getAllResponseHeaders() returns response header of a request.

Actual behavior

When a $redirect filter is applied:

  • XMLHttpRequest.prototype.status returns 0.
  • XMLHttpRequest.prototype.getResponseHeader('content-length') returns anull.
  • XMLHttpRequest.prototype.getResponseHeader('expires') returns null.
  • XMLHttpRequest.prototype.getAllResponseHeaders() returns an empty string.

When a scriptlet filter is applied:

  • All methods and property return empty data.

uBO version

1.47.2

Browser name and version

Mozilla Firefox Developer Edition 111.0b7

Operating System and version

Ubuntu 22.10

Activity

  1. JobcenterTycoon commented on Mar 1, 2023

    @JobcenterTycoon
  2. changed the title [-]'XMLHttpRequest.prototype.getResponseHeader' issue in scriptlet and redirect[/-] [+]'XMLHttpRequest.prototype.getResponseHeader()' issue in scriptlet and redirect[/+] on Mar 1, 2023
  3. ghost added
    enhancementNew feature or request
    on Mar 1, 2023
  4. gorhill commented on Mar 1, 2023

    @gorhill
    Member

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


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

  5. piquark6046 commented on Mar 1, 2023

    @piquark6046
    MemberAuthor

    Added into Steps to Reproduce.

  6. piquark6046 commented on Mar 1, 2023

    @piquark6046
    MemberAuthor

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

    Footnotes

    1. Brave 1.48.171 ↩

  7. gorhill commented on Mar 1, 2023

    @gorhill
    Member

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

  8. uBlock-user commented on Mar 1, 2023

    @uBlock-user
    Member

    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.

  9. gorhill commented on Mar 1, 2023

    @gorhill
    Member

    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.

  10. piquark6046 commented on Mar 1, 2023

    @piquark6046
    MemberAuthor

    Fixed.

  11. MasterKia commented on Mar 8, 2023

    @MasterKia
    Member

    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;
            }
  12. MasterKia commented on May 25, 2023

    @MasterKia
    Member
  13. added a commit that references this issue on Aug 8, 2023
  14. JobcenterTycoon commented on Aug 14, 2023

    @JobcenterTycoon
  15. ghajini commented on Aug 17, 2023

    @ghajini

    @gorhill
    are you planning to support no-fetch-if to return actual response?
    this is required for case here
    uBlockOrigin/uAssets#19295

    firefox

  16. piquark6046 commented on Aug 17, 2023

    @piquark6046
    MemberAuthor

    @ghajini #2526
    Did you mean this issue?

  17. ghajini commented on Aug 17, 2023

    @ghajini

    yes for no-fetch-if

  18. uBlock-user commented on Aug 17, 2023

    @uBlock-user
    Member

    What was done for no-xhr-if in gorhill/uBlock@bf591d9 needs to be done for no-fetch-if.

  19. added a commit that references this issue on Dec 10, 2023
  20. uBlock-user commented on Dec 11, 2023

    @uBlock-user
    Member

    'expires' was not added or is missing..

  21. gorhill commented on Dec 11, 2023

    @gorhill
    Member

    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.

  22. JobcenterTycoon commented on Jan 10, 2024

    @JobcenterTycoon

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

  23. MasterKia commented on Jan 10, 2024

    @MasterKia
    Member

    I can update the wiki in a week or so.

  24. JobcenterTycoon commented on Jan 23, 2024

    @JobcenterTycoon

    Still not updated

  25. gorhill commented on Sep 30, 2025

    @gorhill
    Member

    Any further improvements to prevent-xhr will have to be done through real world filtering issues.

  26. added a commit that references this issue on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions