1 | initial version |
To change the URL in a Chrome extension, follow these steps:
Open the manifest.json file of your extension in a text editor.
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/"
]
Save the manifest.json file.
Open the background.js file of your extension in a text editor.
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"}.
Save the background.js file.
Load the updated extension by going to chrome://extensions/, enabling developer mode, and clicking "Load unpacked" to select the folder containing your updated extension.
Open a new tab and navigate to your desired URL to confirm that the changes have taken effect.