Search code examples
google-chrome-extension

How to match multiple domain variations in Chrome Extension?


I need to macth below example domains for the Chrome extension.

https://network1.com
https://network2.com

Rather than hardcoding, is it possible to match the domains with regular expression?

"content_scripts": [
    {
     "matches": [
        "*://network*.com/*",
      ]
   }

I have tried this but Chrome throws error.


Solution

  • As the documentation mentions,

    https://*foo/bar is a bad (invalid) pattern because * in the host can be followed only by a . or /.

    So, you cannot use a substring match pattern like yours.

    However, if the dynamic part in URL was a sub-domain like 1.network.com and 2.network.com, you could use the pattern https://*.network.com.