Code: Select all
Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService).addObserver({
observe: function(aSubject, aTopic, aData) {
var channel = aSubject.QueryInterface(Ci.nsIHttpChannel);
if (channel.URI.spec == "http://www.example.com/test.js?v=abcdef") {
channel.URI.spec = "http://www.example.com/test.js";
}
}
}, "http-on-modify-request", false);
Now, although the code does not throw an error, channel.URI.spec seems to remain unchanged despite reassignment. Inspecting the channel.URI object only shows a getter for spec so it's possible that spec was made read-only (although I could not find any public info relevant to such a change).
I checked the nsIURI docs at https://developer.mozilla.org/en-US/doc ... ace/nsIURI and, although some attributes like originCharset are indeed marked as read-only, spec is not marked as such; but then again, the docs haven't been updated since late 2015, so a lot might have changed since then.
I tried to use channel.redirectTo() (https://developer.mozilla.org/en-US/doc ... redirectTo()) instead:
Code: Select all
channel.redirectTo(channel.URI.mutate().setSpec("http://www.example.com/test.js").finalize());
Code: Select all
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://assets-cdn.github.com/assets/mobile-fe9d20f9494a.js. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Any suggestions as to either
* disabling CORS for a specific set of domains,
* getting the channel.URI.spec = "alternative-url" approach working back again (without downgrading FF), if at all possible, or
* a different way to dynamically rewrite URLs being requested by pages, from within the browser itself
would be much appreciated