Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting a url to a local file using the webRequest api for chrome extensions

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...?

like image 526
ranjez Avatar asked Nov 14 '12 13:11

ranjez


1 Answers

  1. First, you must put your file inside the extension folder (or inside a subfolder of the extension folder).

  2. 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.

like image 160
ibrahim mahrir Avatar answered Oct 24 '22 11:10

ibrahim mahrir