6

I'm trying to build a basic extension that injects an alert script in to every page loaded. But it seems that the script is injecting only to some pages (most pages it's not injected in to), and I couldn't find a pattern in how it picks the pages to get injected to.

This is the manifest:

  {
        "name": "TestingTest",
        "version": "0.1.1",
        "description": "Testing Tests!",
        "manifest_version": 2,
        "content_scripts": [
            {
                "matches": ["http://*/", "https://*/"],
                "js": ["content.js"],
                "run_at": "document_end"
            }
        ],
        "background": {
            "page": "background.html"
        },
        "permissions": [
            "tabs",
            "http://*/", "https://*/",
            "cookies"
        ],
        "icons": {
            "16": "my_icon_64.png",
            "32": "my_icon_64.png",
            "48": "my_icon_64.png",
            "128": "my_icon_64.png"
        }
    }

and this is ccontent.js:

alert("content script");
console.log("content script")

I'm getting the alert only on a select few pages. The pages that it's injected in to seem to vary if I load the extension in different Chrome profiles.

1
  • Thank you for writing a good question that includes enough code snippets for potential answerers to see the issue quickly.
    – sowbug
    Jan 7, 2014 at 15:46

1 Answer 1

13

Your content script is probably loading only on pages where the pathname is just /. Add an extra * at the end of your url patterns:

"matches": ["http://*/*", "https://*/*"]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.