Google Chrome content_script not loading JS on matching URL

858 views Asked by At

Even after searching a lot of topics in stack overflow, nothing helped me to fix this error...

I'm trying to create an extension, and for now there are simple codes in it, but unfortunately, the console is not logging 'Hello, world!' from the content_scripts file.

manifest.json

{
    "manifest_version": 2,

    "name": "Example",
    "shortname": "exmpl",
    "description": "__MSG_appDesc__",
    "version": "0.0.1",
    "default_locale": "en",
    "author": "Mateus Akino",
    "icons": {
        "16": "i16x.png",
        "48": "i48x.png",
        "128": "i128x.png"
     },
    "homepage_url": "http://example.com/",
    "browser_action": {
        "default_icon": "i32x.png",
        "default_popup": "popup.html"
    },
    "update_url": "http://example.com/update.xml",
    "chrome_url_overrides": {
        "newtab": "newtab.html"
    },
    "content_scripts": [{
        "matches": ["*://*.youtube.com/*"],
        "js": ["execute.js"],
        "run_at": "document_end"
    }],
    "background": {
        "scripts": ["background.js"]
    },
    "permissions": [
   "activeTab", "tabs", "i18n", "management", "webNavigation", "<all_urls>"
   ]
}

execute.js

console.log("Hello, world!");

background.js

chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
    chrome.tabs.executeScript(null, {
        file: "execute.js"
    });
});
1

There are 1 answers

1
Mateus On BEST ANSWER

I fixed the problem, so I'm posting it here if someone else has the same issue.

Looks like the code was fine, the problem was the way I was loading the extension...
As I'm using 'Load unpacked extension', my manifest.json wasn't updating just by disabling and enabling it (neither by using Refresh extensions now).

So I removed the extension, loaded it again and it's working normally now.