Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To change the URL in a Chrome extension, follow these steps:

  1. Open the manifest.json file of your extension in a text editor.

  2. Locate the "permissions" block and add the URL you want to access. For example, if you want to access http://www.example.com, add the following line to the "permissions" block:

"permissions": [
   "http://www.example.com/"
]
  1. Save the manifest.json file.

  2. Open the background.js file of your extension in a text editor.

  3. Add the following code to your background.js file to make a request to the desired URL:

chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
        return {redirectUrl: "http://www.example.com"};
    },
    {urls: ["*://www.example.com/"]},
    ["blocking"]
);

This code redirects any request made to http://www.example.com to the specified URL in return {redirectUrl: "http://www.example.com"}.

  1. Save the background.js file.

  2. Load the updated extension by going to chrome://extensions/, enabling developer mode, and clicking "Load unpacked" to select the folder containing your updated extension.

  3. Open a new tab and navigate to your desired URL to confirm that the changes have taken effect.