2
votes

I'm learning about Chrome extensions and making some hello world apps. I'm working on Content scripts here.

Firstly, my app is very simple, it is just a manifest that loads a content script.

This is the manifest

{
  "name": "turn all th into TH",
  "version": "1.0",
  "permissions": [
    "http://*/*"
  ],
  "manifest_version": 2,

 "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["contentScriptFirstApp.js"]
    }
  ]
}

and the contentscript is just one line

alert('hello');

Now i run this, the alert box shows up every time a page is loaded.

However, the strange thing is, although the code is running, i cannot find the ContentScript in the Developer tools.

It's only when I make a slight adjustment to my manifest, changing the matches parameter so that instead of allowing , it only matches with http files as below that I can see the content script in the developer tools.

{
  "name": "turn all th into TH",
  "version": "1.0",
  "permissions": [
    "http://*/*"
  ],
  "manifest_version": 2,

 "content_scripts": [
    {
      "matches": ["http://*/*"],
      "js": ["contentScriptFirstApp.js"]
    }
  ]
}

Just curious why this is. In both cases, the code is running and showing the alert box, but why is it only when the content script pages has the "matches" parameter set as http pages only that it starts to show up in the developer tools?

1

1 Answers

1
votes

Pretty sure this is just coincidence and a glitch I often see when first loading an extension.

When I use your "<all_urls>" manifest, I see the contentScriptFirstApp.js just fine in the Sources tab of the dev tools. I can switch to the content script context just fine.

But it seems that sometimes when first installing an extension from disk, that the first tab's dev tools don't always see it. I and others have seen this problem but I haven't figured out a reliable way to duplicate the issue on demand.

Whatever the cause, closing that tab and opening a new one always fixes it (so far). So probably there was enough going in between when you changed the manifest that the extension coincidentally made an appearance in dev tools. Like I said, the manifest works and the extension shows up for me, irregardless of the matches settings.