Limit Chrome Extension to certain URLs?

google-chrome, google-chrome-extension

Solution

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"]
    }
  ],

Problem

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?

Original source