I am writing a chromium browser extension and trying to change part of the URL in a GET request. But I do not understand how to return the modified parameter? It is important that only the parameter in the URL is changed, and the rest of the headers remain.

I need to change the β€œ blabla ” part to β€œ stopbla ”. For example:

Before -----: http://site.com/index.php?bla=blabla&end=false

After: http://site.com/index.php?bla=stopbla&end=false

Replacement is successful. But Fidler shows that the sent values ​​have not changed.

I cannot use the following construct, as it only works in onBeforeSendHeaders . And also because the URL parameter is outside the requestHeaders parameter:

return {requestHeaders: details.requestHeaders};

View JSON request tree

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"]}, 

    1 answer 1

    By trial and error, I found the solution.

    In the parameter you need to specify only 'blocking' and nothing else! It is important!

    var opt_extraInfoSpec = ['blocking'];

    The listener method use the following:

    chrome.webRequest.onBeforeRequest.addListener

    And in callback to return redirectUrl with the changed URL:

    return {redirectUrl: modified_url };