How to modify URL through chrome.webRequest.onBeforeRequest?
-
I'm writing an expansion for the browser chromium and trying to change. part URL In GET. But I don't understand how to return the modified parameter? It's important that only change. parameter in URLand the rest of the heds stayed.
I need to change the part.blablaOn "stopbla" For example:
Do--
What am I doing wrong?
background.js (part)
var callback = function (details) { if (details.url.indexOf('blabla') > -1) {
bkg.console.log('++ Yes: ' + JSON.stringify(details.url)); details.url = details.url.replace('blabla', 'stopbla'); } return {url: details.url};
};
var filter = {urls: ["http:///", "https:///"], tabId: currentTabId};
var opt_extraInfoSpec = ['requestBody', "blocking"];chrome.webRequest.onBeforeRequest.addListener(
callback, filter, opt_extraInfoSpec);
manifest.json (part)
"permissions": [ "tabs","background", "webRequest", "webRequestBlocking", ":///"],
"background": {"scripts": ["background.js"]},
-
The method of sampling and error, it's the solution.
In the parameter, only 'blocking' And nothing else! It's important!
var opt_extraInfoSpec = ['blocking'];
The following method shall be used:
chrome.webRequest.onBeforeRequest.addListener
And callback. redirectUrl c modified URL:
return {redirectUrl: modified_url?