0

In my google chrome extension i want to insert a JS file in a wild card url using the include_globs but it is not working

"content_scripts": [
{
  "matches": [
    "http://stackoverflow.com/*"
  ],
  "include_globs": [
    "*google*"
]

  "js": [
    "scripts/content-scripts/utils.js",

  ]
},

This script is inserted in stackoverflow but not in google.

Omair Shamshir
  • 2,126
  • 13
  • 23

1 Answers1

1

You misunderstand how globs work.

They offer additional filtering after matches filter is applied.

include_globs
array of string
Optional. Applied after matches to include only those URLs that also match this glob. Intended to emulate the @include Greasemonkey keyword. See Match patterns and globs below for more details.

So your manifest applies to https://stackoverflow.com/questions/tagged/google-chrome-extension but not https://www.google.com/ or http://stackoverflow.com/

I understand your desire to use a glob: you basically want a google.* pattern. That's not allowed due to inherent security risks attached.

You can see the question Match pattern for all google search pages to see why and what are the possible workarounds.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • @Xan, How to use regex for globs? `"include_globs":["/^https?://www\\.example\\.com/.*$/"]` don't seem to work. – Pacerier Oct 17 '17 at 10:23
  • @Pacerier You don't. It's not a regex engine that's behind it - see docs linked for syntax. If you need more powerful processing, you'll need to do it in the script itself after injection. – Xan Oct 17 '17 at 10:30
  • @Pacerier Alternatively, use `declarativeContent` API. It allows regex matching. https://developer.chrome.com/extensions/declarativeContent#type-PageStateMatcher – Xan Oct 17 '17 at 10:32
  • Nevermind the last part. Chrome never took declarative content scripts out of Dev – Xan Oct 17 '17 at 10:35