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"
    });
});
4
  • 1
    I think spfdone event is a better solution because it doesn't require the background page at all. Commented Dec 23, 2016 at 1:38
  • Which page are you testing on and can you ensure chrome.webNavigation.onHistoryStateUpdated.addListener is called? Commented Dec 23, 2016 at 1:39
  • @HaibaraAi I added 'console.log("Test");" to it, and no, it doesn't seem to be called. Commented Dec 23, 2016 at 1: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 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. Commented Dec 23, 2016 at 2:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The manifest of an unpacked extension is reloaded when you click Reload (Ctrl-R) using a mouse.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.