Repository navigation
'XMLHttpRequest.prototype.getResponseHeader()' issue in scriptlet and redirect #2518
Description
Activity
Similar: uBlockOrigin/uAssets#16430 (comment)
- changed the title
[-]'XMLHttpRequest.prototype.getResponseHeader' issue in scriptlet and redirect[/-][+]'XMLHttpRequest.prototype.getResponseHeader()' issue in scriptlet and redirect[/+]on Mar 1, 2023 Probably because on Firefox
xhrrequests are redirected usingdata:URI.
Also, please transcribe here the filter to use for your repro case.
Added into
Steps to Reproduce.I get exceptions being raised. Probably should move your
<script>tag just before</body>.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.
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.
Fixed.
Similar (the site uses
response.statusas bait):
https://github.com/uBlockOrigin/uAssets/issues/14204let 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; }
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
emptyresponse.
Anyway, AdGuard's fix:
AdguardTeam/Scriptlets@531ea12#diff-ff559a075c8491c9b6a0cdeea5aceee74950e68eb2423435ab3afaa87c4452ccR28Reacted by Κριστιάν3β@gorhill
are you planning to supportno-fetch-ifto return actual response?
this is required for case here
uBlockOrigin/uAssets#19295firefox
yes for
no-fetch-ifWhat was done for
no-xhr-ifin gorhill/uBlock@bf591d9 needs to be done forno-fetch-if.Reacted by ghajini and JobcenterTycoon- added a commit that references this issue
on Dec 10, 2023 'expires' was not added or is missing..
Adding
expiresis 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.@gorhill will the Resources-Library get a update? The latest features like
length:are missing.I can update the wiki in a week or so.
Reacted by JobcenterTycoon and iam-py-testStill not updated
Any further improvements to
prevent-xhrwill have to be done through real world filtering issues.Reacted by JobcenterTycoon- added a commit that references this issue
on Jul 16, 2026
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.
Expected behavior
XMLHttpRequest.prototype.statusreturns200.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
$redirectfilter is applied:XMLHttpRequest.prototype.statusreturns0.XMLHttpRequest.prototype.getResponseHeader('content-length')returns anull.XMLHttpRequest.prototype.getResponseHeader('expires')returnsnull.XMLHttpRequest.prototype.getAllResponseHeaders()returns an empty string.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