1

Is it possible to create a link that the user clicks (say in an email) which opens a Chrome extension that's already installed?

Or, put it in another way, is it possible to develop a Chrome extension that handles how a link is shown (e.g. inside Gmail.com or other sites), that whenever the user clicks it, the extension shows up instead of the user being directed to a site?

I've come across articles talking about custom protocols:

But what if the extension is not installed, how do you fall back to HTTP?

<a href="mycustproto:somevalue">http://mywebsite.com/somevalue</a>

Makyen
  • 31,849
  • 12
  • 86
  • 121
Rommel Paras
  • 325
  • 6
  • 20
  • It would be fairly easy for the extension to watch for a very specific (HTTP/HTTPS) URL to be opened, cancel the request and open the extension instead. The URL could be one that you have set up on a server that will show something like "You don't have installed. If you want this to work, you will need to [click here] to install it." – Makyen Feb 23 '17 at 00:24
  • Asking for examples (an of-site resource) would make this question off-topic. I have edited the question to remove that request. – Makyen Feb 23 '17 at 01:05

1 Answers1

1

This could easily be done with a webNavigation.onBeforeNavigate listener which listens for a specific URL. When the URL is encountered, it can cause a specific page within the extension to be opened instead.

Quickly prototyping this, the code could look something like (untested, may have errors):

chrome.webNavigation.onBeforeNavigate.addListener(function(details){
    chrome.tabs.update(details.tabId,{url:chrome.runtime.getURL('/thePageIWant.html'});
},{url:[
    {urlEquals:'http:/www.domain-for-my-extension.com/invokeMyExtension.html'}
]});

References:

Makyen
  • 31,849
  • 12
  • 86
  • 121
  • Thanks for pointing me in the right direction @Makyen. I modified the code to something that works now: `chrome.webNavigation.onBeforeNavigate.addListener(function(details) { if(details.url.indexOf("upfi.re") !== -1) { chrome.tabs.update(details.tabId, { url: chrome.runtime.getURL('/thePageIWant.html#url=') + details.url }); } });` However, is it correct that I can't trigger the popup like [this one](http://prntscr.com/eckvp0) but I can open a new tab? – Rommel Paras Feb 23 '17 at 21:05
  • 1
    @RommelParas, You can, of course, [open a new tab, or window](http://stackoverflow.com/a/40839094/3773011). You can not programmatically open the actual browser/page action popup. However, you can [open a window that looks and acts very much like one](http://stackoverflow.com/a/40296092/3773011) (I need to move the code in that answer into a new answer for the canonical programmatically opening "the popup" question). – Makyen Feb 23 '17 at 21:16
  • 1
    @RommelParas, If you are wanting to only act on URLs that contain `'upfi.re'`, then it would be better to use a [` urlContains`](https://developer.chrome.com/extensions/webNavigation#property-urlType-urlContains) property on the UrlFilter. Doing so will result in your code only being called for the events that are of interest to you. – Makyen Feb 23 '17 at 21:21