1

For google chrome extension i need to be able to detect if user use chrome browse to open .html file.

I tried different method but it seem i do not get an event

"permissions": ["webRequest","browsingData", "fileSystemProvider"],
  "file_system_provider_capabilities": {
       "configurable": true,
       "watchable": true,
       "source": "file"
},

I tried to intercept in webRequest

chrome.webRequest.onBeforeSendHeaders.addListener(function(info){
// info.url does not give me the file.html which opened


)};

I tried with different methods for file event handling but none get fire

    chrome.fileSystemProvider.onOpenFileRequested.addListener(function(file){
    console.log("open file");
});
chrome.fileSystemProvider.onReadFileRequested.addListener(function(file){
    console.log("read file");
});
chrome.fileSystemProvider.onExecuteActionRequested.addListener(function(){
    console.log("execute file");
});

Thanks in advance for any help

user332951
  • 359
  • 1
  • 3
  • 18
  • Use chrome.tabs.onUpdated listener. The webRequest is for web requests, obviously, and fileSystemProvider is to provide virtual file systems. – wOxxOm May 18 '18 at 20:33
  • I do get an event for tabs.onUpdated but i can't see the file name. The idea is when user open html file from local i should be able to detect and scan the content. – user332951 May 18 '18 at 21:23
  • A tab URL is the file name so there should be no problem seeing it if you have `"permissions": [""]` in manifest.json (or `file://*`). The documentation should have examples. – wOxxOm May 18 '18 at 21:48
  • thank you much for your comment, it did give me some hint. What i have right now for permission is "*://*/" how ever it is not enough I also need to include "file://*" . So now I am be able to capture file protocol in chrome.webRequest.onBeforeRequest. – user332951 May 19 '18 at 17:24

1 Answers1

1

Much thank you for wOxxOm to give me a hint. What I currently have in my permission is ":///". I need to include "file://*" in the permission. I thought the *: should be good enough but not in this case. So right now I am be able to see file:// protocol in chrome.webRequest.onBeforeRequest

user332951
  • 359
  • 1
  • 3
  • 18
  • I tried out the suggested technique I didn't succeeded. I see a lot of requests which the page does - .js and .css files, but not the .html as such, not the first request. Can you write the code which intercepts the request to a local file when it's opened via the browser, please? – RussCoder Mar 23 '19 at 09:57
  • I was using Firefox and it turned out that Firefox doesn't fire the event when a local file is opened, but Opera (and probably Chrome too) does. By the way, Firefox fires onBeforeNavigate event when a local file is opened, while Opera doesn't. – RussCoder Mar 23 '19 at 13:58