I'm having trouble using the webRequest api for chrome extensions to redirect a url
chrome.webRequest.onBeforeRequest.addListener(function(details) {
return {
redirectUrl : "file:///C:/hello.html"
};
}, {
urls : ["<all_urls>"]
}, ["blocking"]);
I can redirect to any http or https address but not a file location anyone know why...?
First, you must put your file inside the extension folder (or inside a subfolder of the extension folder).
Then, you must declare it as a "web_accessible_resources"
in the manifest file.
Example:
If your extension folder is MyExt, and the file you want to use is "MyExt/path/to/file.html"
. Then you should add this to the manifest file:
"web_accessible_resources": [
"path/to/file.html"
]
In general, any file that will be used outside the extension should be declared in the "web_accessible_resources"
array.
Note that the declaration is just the relative path of the file inside the extension folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With