1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-05-20 20:23:37 +12:00
This commit is contained in:
Raymond Hill 2018-02-04 09:10:17 -05:00
parent 55b9f1c645
commit 335709bc50
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 26 additions and 1 deletions

View file

@ -103,6 +103,7 @@ var requestStatsFactory = function() {
var rawSettingsDefault = {
contributorMode: false,
disableCSPReportInjection: false,
enforceEscapedFragment: true,
placeholderBackground:
[
'url("data:image/png;base64,',

View file

@ -53,7 +53,10 @@ var onBeforeRootFrameRequestHandler = function(details) {
// Not blocked
if ( !block ) {
// rhill 2013-11-07: Senseless to do this for behind-the-scene requests.
let redirectURL = maybeRedirectRootFrame(requestHostname, requestURL);
if ( redirectURL !== requestURL ) {
return { redirectUrl: redirectURL };
}
µm.cookieHunter.recordPageCookies(pageStore);
return;
}
@ -72,6 +75,27 @@ var onBeforeRootFrameRequestHandler = function(details) {
/******************************************************************************/
// https://twitter.com/thatcks/status/958776519765225473
var maybeRedirectRootFrame = function(hostname, url) {
let µm = µMatrix;
if ( µm.rawSettings.enforceEscapedFragment !== true ) { return url; }
let block1pScripts = µm.mustBlock(hostname, hostname, 'script');
let reEscapedFragment = /[?&]_escaped_fragment_=/;
if ( reEscapedFragment.test(url) ) {
return block1pScripts ? url : url.replace(reEscapedFragment, '#!') ;
}
if ( block1pScripts === false ) { return url; }
let pos = url.indexOf('#!');
if ( pos === -1 ) { return url; }
let separator = url.lastIndexOf('?', pos) === -1 ? '?' : '&';
return url.slice(0, pos) +
separator + '_escaped_fragment_=' +
url.slice(pos + 2);
};
/******************************************************************************/
// Intercept and filter web requests according to white and black lists.
var onBeforeRequestHandler = function(details) {