javascript - Google chrome api javascript 检测在浏览器中打开的文件

标签 javascript google-chrome google-chrome-extension google-chrome-app chrome-app-developer-tool

对于 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/

相关文章:

javascript - 带有 queryBuilder 的日期选择器

javascript - Document.querySelector 返回 null 直到使用 DevTools 检查元素

JavaScript 函数返回 undefined,调试时除外

javascript - 基于浏览器的 session 计时器

javascript - 不断检查元素的长度,如果为 1 则执行操作

javascript - 获取 SRC 本身包含特定单词的脚本标签的完整 src

javascript - 如何通过打开新窗口而不是从当前页面重定向用户来执行 OAuth 请求?

javascript - 自定义 ES6 JavaScript 错误问题

css - 如何让 Open Sans Light 在 Chrome 中运行?

javascript - Chrome 的 HTML5 Web 数据库在某些 Windows 配置上非常慢