Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 968
MeLight Avatar asked Jan 07 '14 09:01

MeLight


People also ask

Can Chrome extension read page content?

To use Read Aloud, navigate to the web page you want to read, then click the Read Aloud icon on the Chrome menu. In addition, the shortcut keys ALT-P, ALT-O, ALT-Comma, and ALT-Period can be used to Play/Pause, Stop, Rewind, and Forward. You may also select the text you want to read before activating the extension.

What is content script Chrome extension?

A content script is a part of your extension that runs in the context of a particular web page (as opposed to background scripts which are part of the extension, or scripts which are part of the website itself, such as those loaded using the <script> element).


1 Answers

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://*/*"]
like image 143
rsanchez Avatar answered Oct 10 '22 15:10

rsanchez