对于 google chrome 扩展,我需要能够检测用户是否使用 chrome 浏览器打开 .html 文件。
我尝试了不同的方法,但似乎我没有得到一个事件
"permissions": ["webRequest","browsingData", "fileSystemProvider"],
"file_system_provider_capabilities": {
"configurable": true,
"watchable": true,
"source": "file"
},
我尝试在webRequest中拦截
chrome.webRequest.onBeforeSendHeaders.addListener(function(info){
// info.url does not give me the file.html which opened
)};
我尝试了不同的文件事件处理方法,但没有一个成功
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");
});
在此先感谢您的帮助
最佳答案
非常感谢 wOxxOm 给我提示。我目前获得许可的是“:///”。我需要在权限中包含“file://*”。我认为 *: 应该足够好,但在这种情况下不是。所以现在我可以在 chrome.webRequest.onBeforeRequest 中看到 file://协议(protocol)
关于javascript - Google chrome api javascript 检测在浏览器中打开的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50418677/