0

I'm brand new to Chrome Extensions, but it looks like something I could have fun with so I'm trying to figure out what I have to work with.

After reading the documentation and looking at some examples, I'm curious what the best way would be to trigger the page_action icon based on a tab URL. After doing some reading, I came across two examples so far:

First there is the page action by URL as described here. It looks like it uses declarativeContent which I don't fully understand even after reading the documentation. If someone has a better way of explaining it, I'm all ears.

The second was is to do something like what's mentioned here. To me, doing something like this if (tab.url.indexOf('http://specificsite.com') == 0) makes more sense than the things that the declarativeContent method was doing.

Is there a better way to do this than these 2 approaches? If not, what is the best way to trigger a page_action by URL?

Thanks!

Community
  • 1
  • 1
joshft91
  • 1,755
  • 7
  • 38
  • 53
  • When you say "trigger the page_action" you just mean show your page_action in the url bar right? Or do you mean run the associated code? – James Aug 13 '14 at 14:10
  • Correct, yes. Eventually I'll be running some code when the `page_action` is clicked, but for now I only want to show the `page_action` icon when a tab URL matches something specific. Thanks. – joshft91 Aug 13 '14 at 14:15
  • Have you read the docs for declarativeContent? That should clear things up a little bit: https://developer.chrome.com/extensions/declarativeContent – Rob W Aug 13 '14 at 14:37
  • I did, and it makes some sense. It helped that I read it again...there's just many ways to do the same thing and I'm not sure what's best. – joshft91 Aug 13 '14 at 14:43
  • The only time I've ever used a page action I'm fairly sure it was the second way you mentioned. `declarativeContent` (from reading the docs) seems to just be an uglier looking way to do the same thing with the benefit of it being less scary for the user to install. Some people get quite spooked by the amount of permissions you can end up having to ask for your extension to have so it's nice of google to offer this way to cut back on them. – James Aug 13 '14 at 14:44
  • That's what I was thinking too, judgeja. A nice way to sum that up - thanks! – joshft91 Aug 13 '14 at 16:29
  • `declarativeContent` is not just "ugly", but also more efficient. I have shown and explained sample code for both methods at https://stackoverflow.com/a/20856789. – Rob W Aug 13 '14 at 16:41

0 Answers0