amp343
amp343

Reputation: 1056

Limit Chrome Extension to certain URLs?

Is there a way to limit a Chrome extension to only run on certain urls?

Say I want the extension to run only if the domain is Amazon.com. I realize you can put a check at the top of the scripts, then execute the rest of the script only if the check matches.

However, can you prevent the extension from running at all?

Upvotes: 37

Views: 21572

Answers (3)

amp343
amp343

Reputation: 1056

Welp, it figures I would find the answer to this right after posting the question, even though I have been stuck for a while...

Archive of version of docs originally linked in answer: http://code.google.com/chrome/extensions/content_scripts.html

Analog page for Manifest V2 (though see also V3): https://developer.chrome.com/docs/extensions/mv2/content_scripts/

In manifest.json:

  "content_scripts": [
    {
      "matches": ["http://*.nytimes.com/*"],
      "exclude_matches": ["*://*/*business*"],
      "js": ["contentScript.js"]
    }
  ],

Upvotes: 27

Wernight
Wernight

Reputation: 37678

As a user, with Chrome 71 (or maybe even before) with chrome://flags/#extension-active-script-permission (you may need to enable User consent for extension scripts flag) allows you to right click extension icons and select "This can read and change site data" then you can choose:

  • When you click the extension
  • On current-domain-name.com
  • On all sites (default)

enter image description here

This way you can limit an extension to only run on certain domains very quickly.

Upvotes: 9

Joe Fusion
Joe Fusion

Reputation: 41

There's a Chrome extension for this: Extension Automation. I had gone the route of modifying manifests before, but this is easier.

Upvotes: -1

Related Questions