MeLight
MeLight

Reputation: 5575

Chrome extension content script is not injecting in to most pages

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.

Upvotes: 6

Views: 4318

Answers (1)

rsanchez
rsanchez

Reputation: 14657

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://*/*"]

Upvotes: 13

Related Questions