I have a Chrome Extension that uses chrome.webRequest.onBeforeRequest.addListener to load patched scripts/ redirect loading of some scripts to a different site. chrome.webRequest ideally suits me because it helps me to load "patched" script instead of original one, not on top of it.
chrome.webRequest.onBeforeRequest.addListener(function(details){
var originalUrl = details.url;
console.log('originalUrl: ' + originalUrl);
blockingResponse = {};
if (originalUrl fits my condition) {
blockingResponse.redirectUrl = originalUrl.performSomeLogicToGetNewUrl();
console.log('redirectUrl: ' + blockingResponse.redirectUrl);
}
return blockingResponse;
},
{urls: [ "<all_urls>" ]},['requestBody','blocking']);
I want to move to a solution that would be suitable for more than one browser and researching if this can be achieved with greasemonkey/tampermonkey, but no luck so far. Does anyone have a similar experience?