Is there any way to redirect requests without record the original URL in history? Consider that the original URL is pasted into the address bar, so it’s not about DOM manipulation.
I’ve always used redirector_ui.uc.js, but now that I’ve activated e10s, the original URL is recorded on history as well as the redirected one. The redirection still works, there is no connection to the original URL, but somehow it’s recorded in history.
I’ve tested several redirection extensions, even WebExtensions, and all of them also record the original URL.
If I disable e10s, this problem disappears. Is this a bug?
Code to reproduce using WebRequest (but this way the original URL is recorded even without e10s; for transparent redirect you run redirector_ui.uc.js):
var {WebRequest} = Cu.import("resource://gre/modules/WebRequest.jsm", {});
function redirectAsync (requestDetails) {
if (/utm/.test(requestDetails.url)) {
console.log("Redirecting: " + requestDetails.url);
return new Promise((resolve, reject) => {
resolve({redirectUrl: 'http://www.example.com/'});
});
}
}
WebRequest.onBeforeRequest.addListener(redirectAsync, {urls: new MatchPatternSet(["http://www.example.com/*"])}, ["blocking"]);
Solved implementing nsIContentPolicy (shouldLoad) in content process (Services.ppmm.loadProcessScript). With e10s this is no longer handled in chrome process, except for internal pages (chrome://, about:).
The original URL request is rejected by Ci.nsIContentPolicy.REJECT_REQUEST, then the loadURI function creates a new request on the same channel with the redirected URL.
But after bug 1331740 patch, node.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation) doesn’t work anymore.
So now how could I get some reference of the tab/channel where the original request was made to then be able to call loadURI function?
If WebExtensions didn’t have this “bug” of recording pre-redirected URLs in history, maybe I wouldn’t have to resort to that.
A workaround would be to use loadFrameScript instead of loadProcessScript, then content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).loadURI, but this is not recommended:
Services.mm.addMessageListener('Redirector', function (m) {
m.target.loadURI(m.data, null, null, null, null);
});
in chrome process.
I’ll use this solution, but I don’t know which is best:
(1) comunicate between chrome and content processes (the solution in this post)
(2) inject the content script much more times using loadFrameScript instead of loadProcessScript (the solution in previous post).
I guess I chose it right, but not sure. Nor if there is a better solution than both.