Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在后台脚本中,browser.tabs.create打开页面,但显示错误:没有匹配{matcheshot:[";<;all_url>;]_Javascript_Storage_Firefox Addon Webextensions - Fatal编程技术网

Javascript 在后台脚本中,browser.tabs.create打开页面,但显示错误:没有匹配{matcheshot:[";<;all_url>;]

Javascript 在后台脚本中,browser.tabs.create打开页面,但显示错误:没有匹配{matcheshot:[";<;all_url>;],javascript,storage,firefox-addon-webextensions,Javascript,Storage,Firefox Addon Webextensions,我的用例非常简单: 单击工具栏上的浏览操作图标 听一下背景脚本中的点击 创建一个新选项卡,其中页面与manifest.json 所述页面在元素中具有关联的javascript文件 下面是应用程序的结构和代码 manifest.json { "description": "app", "manifest_version": 2, "name": "demo", "version": "1.0", "permissions" : [ "activeTab", "t

我的用例非常简单:

  • 单击工具栏上的浏览操作图标
  • 听一下背景脚本中的点击
  • 创建一个新选项卡,其中页面与
    manifest.json
  • 所述页面在
    元素中具有关联的javascript文件

    下面是应用程序的结构和代码

manifest.json

{

  "description": "app",
  "manifest_version": 2,
  "name": "demo",
  "version": "1.0",

 "permissions" : [
    "activeTab", "tabs", "<all_urls>","host"
 ],

"background" :{
   "scripts" : ["bg/background.js"]
},

"browser_action": {
   "default_icon": {
    "16": "icons/page-16.png",
    "32": "icons/page-32.png"
   }
 }
}
app.html

 <!doctype html>
 <html>
 <head>
    <meta charset="utf-8">
    <title>bookmarks</title>
    <!--<link rel="stylesheet" href="css/main.css"> -->
 </head>
 <body>
       <p>before script</p>
       <script src="../js/tabApp.js"></script>
      <p> after script </p>
 </body>
 </html>
输出

- Message from backgroundjs.  background.js:8:2
- hello from the other end  tabApp.js:3:1
- Error: No window matching {"matchesHost":["<all_urls>"]}  (unknown)
-来自backgroundjs的消息。background.js:8:2
-另一端的你好tabApp.js:3:1
-错误:没有窗口匹配{“MatcheHost”:[“”]}(未知)
除了
错误:没有与{“MatcheHost”:[“”]}
匹配的窗口外,应该有输出。我不确定是什么导致了这个错误

到目前为止,我已经做了以下调试工作

  • 添加了权限

请给出您的输入

您能检查一下输出是什么吗

console.log(browser.runtime.getURL("../tab/html/app.html") 

看起来相对路径不是来自manifest.json()

,因此形成的url是:moz-extension://e8e74721-13fd-4b0f-a638-1f5c104b3097/tab/html/app.html web扩展正在运行。我没有任何错误或代码冻结。只是,我很好奇这是什么原因造成的。我试图删除所有扩展,以检查这是否来自其他扩展。但是没有。只有当我运行webextensions时才会发生这种情况
- Message from backgroundjs.  background.js:8:2
- hello from the other end  tabApp.js:3:1
- Error: No window matching {"matchesHost":["<all_urls>"]}  (unknown)
console.log(browser.runtime.getURL("../tab/html/app.html")