Browse Source

fix #940

pull/2/head
Raymond Hill 7 years ago
parent
commit
335709bc50
No known key found for this signature in database GPG Key ID: 25E1490B761470C2
  1. 1
      src/js/background.js
  2. 26
      src/js/traffic.js

1
src/js/background.js

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

26
src/js/traffic.js

@ -53,7 +53,10 @@ var onBeforeRootFrameRequestHandler = function(details) {
// Not blocked // Not blocked
if ( !block ) { 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); µm.cookieHunter.recordPageCookies(pageStore);
return; 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. // Intercept and filter web requests according to white and black lists.
var onBeforeRequestHandler = function(details) { var onBeforeRequestHandler = function(details) {

Loading…
Cancel
Save