本文介绍了firefox addon tabs.executeScript特定页面上的错误没有窗口匹配{" matchesHost":[< all_urls>"]}}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从Chrome扩展移植到Firefox的webextension。 executeScript调用在这个站点上失败。

  https://addons.mozilla.org/en-US/firefox/ 

我在这个网站上测试了多个页面,并且都给出了相同的错误



裸露的最小代码重现这是

popup.js

  document.addEventListener(DOMContentLoaded,function(){
chrome.tabs.query({active:true},function(tabs){
chrome.tabs。执行脚本(tabs [0] .id,{code:console.log('script in'+ document.location.href);},function(r){
if(chrome.runtime。 lastError){
console.log(chrome.runtime.lastError);
document.body.innerHTML ='Execute script Fail。check console';
} else {
document。 body.innerHTML ='执行脚本成功';
}
});
});
});

manifest.json

  {
manifest_version:2,
name:execscript_test,
short_name:execscript_test,
version:0.0.1,

description:desc,
图标:{
19:images / icon19。 png,
38:images / icon38.png,
128:images / icon.png
},

应用程序:{
gecko:{
id:execscript_test@me.com,
strict_min_version:48.0
}
},
$ b $背景:{
scripts:[background.js]
},

permissions:[
标签,
< all_urls>
browser_action:{
browser_style:false,
default_icon:images / icon.png,
default_title: execscript_test,
default_popup:popup.html
}
}

background.js - 文件存在,但为空
$ b popup.html

 <!doctype html> 
< html>
< head>
< meta charset =utf-8/>
< script src =popup.js>< / script>
< / head>
< body>

< / body>
< / html>

关于 https://addons.mozilla.org/en-US/ firefox / addon / engrip-tracker /?src = search 页面我点击浏览器按钮,在浏览器控制台中出现这个错误消息

pre > 错误:无窗匹配{matchesHost:[< all_urls>]}
堆栈跟踪:
异步* @ moz-extension:// 062a83b0-81f1- 42f0-84a8-89ecdc2c08e0 / popup.js:8:4
Async * @ moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:2:2
EventListener.handleEvent * @ moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:1:1

我认为这可能是一些URL方案的问题,但即使在 https://addons.mozilla.org/en-US/firefox/
相同的代码在chrome上没有错误。



我在FF v50上。我每晚都在FF上测试这个(v53.0a1),错误依然存在。



这是这个网站特定的东西吗?或者我在这里错过了什么?

解决方案

这是故意的, https://bugzilla.mozilla.org/show_bug.cgi?id=1310082


I have a firefox webextension ported from chrome extension. The executeScript call fails on this site.

https://addons.mozilla.org/en-US/firefox/

I tested with multiple pages on this site and all are giving the same error

The bare-minimum code to reproduce this is

popup.js

document.addEventListener("DOMContentLoaded", function () {
    chrome.tabs.query({"active": true}, function(tabs) {        
        chrome.tabs.executeScript(tabs[0].id, {"code": "console.log('Script executed in ' + document.location.href);"}, function(r) {
            if(chrome.runtime.lastError) {
                console.log(chrome.runtime.lastError);
                document.body.innerHTML = 'Execute script Fail. check console';         
            } else {
                document.body.innerHTML = 'Execute script Success';         
            }
        });
    });
});

manifest.json

{
    "manifest_version": 2,
    "name": "execscript_test",
    "short_name": "execscript_test",
    "version": "0.0.1",

    "description": "desc",
    "icons": {
        "19": "images/icon19.png",
        "38": "images/icon38.png",
        "128": "images/icon.png"
    },

    "applications": {
        "gecko": {
            "id": "execscript_test@me.com",
            "strict_min_version": "48.0"
        }
    },

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

    "permissions": [
        "tabs",
        "<all_urls>"
    ],
    "browser_action": {
        "browser_style": false,
        "default_icon": "images/icon.png",
        "default_title": "execscript_test",
        "default_popup": "popup.html"
    }    
}

background.js - file is present but it is empty

popup.html

<!doctype html>
<html>
    <head>
        <meta charset="utf-8" />
        <script src="popup.js"></script>
    </head>
    <body>

    </body>
</html>

On https://addons.mozilla.org/en-US/firefox/addon/engrip-tracker/?src=search page I clicked on the browser button and got this error in browser console

Error: No window matching {"matchesHost":["<all_urls>"]}
Stack trace:
Async*@moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:8:4
Async*@moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:2:2
EventListener.handleEvent*@moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:1:1

I thought it could be some url scheme issue but this happens even on https://addons.mozilla.org/en-US/firefox/The same code works without error on chrome.

I am on FF v50. I tested this on FF nightly also (v53.0a1) and the error persists.

Is this something specific to this site? Or am I missing something here?

解决方案

This is deliberate, it is covered in e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=1310082

这篇关于firefox addon tabs.executeScript特定页面上的错误没有窗口匹配{&quot; matchesHost&quot;:[&lt; all_urls&gt;&quot;]}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:03