Search code examples
google-chromegoogle-chrome-extensioncontent-script

How to match multiple sites with the same domain with Chrome extension content scripts


Trying to match content scripts to multiple sites with the same domain but different TLDs results in it only matching to one of the sites:

"content_scripts": [
  {
    "matches": ["https://foo.org/*", "https://foo.com/*"],
    "js": ["content.js"]
  }
],

In this case it's only matching foo.com and not foo.org. Is this behavior documented somewhere, and is there some way to make it match every site in the list?

This also doesn't work:

"content_scripts": [
  {
    "matches": ["https://foo.org/*"],
    "js": ["content.js"],
  },
  {
    "matches": ["https://foo.com/*"],
    "js": ["content.js"],
  }
],

It ends up only matching foo.com.

Screenshot of the Details dialog:

screenshot


Solution

  • I can confirm the permission warnings get compressed into one domain, which is strange and potentially very misleading.

    Think whitehouse.gov and whitehouse.com [Wikipedia, if you're not familiar with the latter], Chrome prefers .com for the permission warning. Seems worth a bug report.

    However, I can't confirm the actual problem of it not being injected. Both forms lead to the content script being injected in my testing.