Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Chrome extension for certain urls?

I'm building my first Chrome extension and was wondering if there's a way for it only to be enabled/displayed on the toolbar when visiting Google Drive?

Reading through the dev guide it looks like I need to either set permissions or content_scripts=>matches in my manifest.json file to something like this:

"permissions" : {"https://drive.google.com/", "http://drive.google.com/"}

or this:

"content_scripts": [
  {
    "matches": ["https://drive.google.com/", "http://drive.google.com/"],
     ...
  }

Neither seem to be working as my extension shows up on every page I visit. Is there another resource I can take a look at?

like image 316
slightlyoverwhelmed Avatar asked Oct 18 '22 14:10

slightlyoverwhelmed


1 Answers

"displayed on the toolbar" sounds like you're talking about a page or browser action. Since you only want some pages, this means you want a page action. If you then want to interact with the DOM, then you’ll need a content script. And you’ll want "matches": ["*://drive.google.com/*"]. The first * equals the two hosts you listed; the second * means "any url with that prefix" and may have been your original problem. See match patterns for more details.

If you don’t need a content script, you have the option to use declarativeContent in your event script to show the page action. And "permissions": ["activeTab", "declarativeContent"].

like image 116
Teepeemm Avatar answered Oct 21 '22 04:10

Teepeemm