1

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"
    });
});
Mateus
  • 4,863
  • 4
  • 24
  • 32
  • 1
    I think [`spfdone` event](http://stackoverflow.com/a/32277150/) is a better solution because it doesn't require the background page at all. – wOxxOm Dec 23 '16 at 01:38
  • Which page are you testing on and can you ensure `chrome.webNavigation.onHistoryStateUpdated.addListener` is called? – Haibara Ai Dec 23 '16 at 01:39
  • @HaibaraAi I added 'console.log("Test");" to it, and no, it doesn't seem to be called. – Mateus Dec 23 '16 at 01:50
  • Please describe the *exact* URL and the *exact* user interaction with the browser UI which you are performing. Describe *exactly* what you are seeing in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) and describe *exactly* what you expect to see. Also, please tell us what you are attempting to accomplish. Right now, all we know is that you are not seeing 'Hello, world!' at some point when you are expecting it, but not when that is. Your code implies that you expect to see it at other times, in addition to when you first load a page. – Makyen Dec 23 '16 at 02:16

1 Answers1

2

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.

Mateus
  • 4,863
  • 4
  • 24
  • 32
  • 1
    The manifest of an unpacked extension is reloaded when you *click* `Reload (Ctrl-R)` using a mouse. – wOxxOm Dec 24 '16 at 11:12