firefox addon tabs.executeScript error on specific pages No window matching {"matchesHost":["<all_urls>"]}
Asked Answered
D

1

0

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": "[email protected]",
            "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?

Dishonesty answered 25/11, 2016 at 5:53 Comment(4)
I have tried your code and also experience the problem on FF52.0a2 (Developer Edition). I have also tried it as just an actionButton without using a popup. The problem still exists in that case (i.e. it is not a problem related to the fact that this is being done in a popup.)Forte
BTW: Your chrome.tabs.query will need at least one additional queryInfo property. Without something restricting this to a single window, you will get multiple entries in your tabs array, if you have more than one window open. This will normally be currentWindow: true, but could be different, or more complex, depending on what you desire. One way or another, you are assuming that the tab you desire is the first one in the array of results. Currently that is not guaranteed based on the parameters you have provided.Forte
While I have not yet tracked this down in the source code, the fact that is done would be directly comparable to Google not permitting scripts to be injected in the Chrome Web Store. Chrome responds with "The extensions gallery cannot be scripted." when this code is used in Chrome on https://chrome.google.com/webstore.Forte
@Forte - oh!, ok. browser vendors blocking script injection on their extension distribution pages seems reasonable Hope this blocking tech is available only to browsers and not websites, else content scripts will become useless soon.Dishonesty
I
0

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

Interdiction answered 26/11, 2016 at 17:25 Comment(1)
Seems like timing and flavor. If it is just addon sites, I can move on with exceptions..Dishonesty

© 2022 - 2024 — McMap. All rights reserved.