webRequest.filterResponseData does not seem to work with 302-redirected scripts
Categories
(WebExtensions :: Request Handling, defect, P3)
Tracking
(Not tracked)
People
(Reporter: twisniewski, Unassigned)
Details
Attachments
(1 file, 1 obsolete file)
|
1.24 KB,
application/zip
|
Details |
I set up a minimal server which 302-redirects the script test.js to test.1234.js, and loads it in a minimal HTML page like this:
<script src="http://localhost/test.js"></script>
Then I made a minimal webExtension which filter-rewrites test.js and test.1234.js, but it does not end up working:
"use strict";
function block(request) {
const { frameId, tabId, url, requestId } = request;
console.log("SHIMMING", url, requestId, "on", tabId, "(", frameId, ")");
const filter = browser.webRequest.filterResponseData(requestId);
filter.onerror = function() {
console.log("ERROR", arguments);
};
filter.onstart = async event => {
const script = `console.log("OVERRULED!");`
filter.write(new Uint8Array(new TextEncoder("utf-8").encode(script)));
filter.close();
console.log("FILTERED", script);
};
return {};
}
chrome.webRequest.onBeforeRequest.addListener(
block,
{urls: ["http://localhost/test.js",
"http://localhost/test.1234.js"]},
["blocking"]
);
In the network panel I see the test.js request being redirected to test.1234.js. In my add-ons background page, I see both requests are being intercepted, and apparently the filter applies to test.1234.js, but I see this in the console when I visit the minimal HTML page above:
Loading failed for the <script> with source “http://localhost/test.js”.
It doesn't appear to be my server config; I get the same results when I try to filter https://www.instagram.com/embed.js on a page like this one, which currently 302-redirects to https://www.instagram.com/static/bundles/es6/EmbedSDK.js/bf4a12bd69f3.js.
I'll see if I can write an in-tree-ready testcase to reproduce this ASAP, but for now I figured I'd file the bug so it's not forgotten.
Comment 1•6 years ago
|
||
Extension + Node.js server to reproduce.
The bug occurs when StreamFilter is attached to the 302 request; it is not needed to have a listener for the redirect target.
STR:
node server.jsto start the server atlocalhost:8080.- Load the extension. The extension will open
localhost:8080. - Open the console.
At step 2, the server will respond with HTML that loads http://localhost/test.js. The extension attaches a StreamFilter. The server responds with 302, and the extension receives filter.onerror with filter.error = "Channel redirected".
At step 3, the following error appears in the console:
Loading failed for the <script> with source “http://localhost/test.js”.
Reproduced with Firefox 77.0a1 build ID 20200419091145. I can even reproduce it on older versions such as Firefox 74.0.
Comment 2•6 years ago
|
||
Comment 3•6 years ago
|
||
The test isn't entirely right as it isn't checking for the changed content, but I've verified that the loading does not fail when the patch in Bug 1595197 is applied.
| Reporter | ||
Comment 4•6 years ago
|
||
Yes, with that patch applied my own tests seem to work fine, so this would appear to be a dupe of that issue.
Updated•6 years ago
|
Updated•6 years ago
|
Description
•