1

We would like to distribute our Chrome Extension using inline installs from our partners' websites. And we'd like to know from inside the extension which website it was installed from. Is there a way we could insert a parameter during the installation process and receive it within the extension? Thanks in advance.

1 Answers1

2

There's no direct way to do it in the chrome inline install API, however there is a way to hook it up that requires a bit of legwork.

Essentially you need 2 things:

  1. The ability to know when a chrome extension install has successfully completed for your extension on a partner site.
  2. A mechanism, from the partner's site, to send a message to your chrome extension.

The 1st is easy and part of the chrome install API, just use the successCallback function to the install API as listed here.

Now that you have a point in time where you know an install has happened, getting the URL over to your extension is kind of convoluted. The easiest way to do this is to send a custom javascript event with the URL in the event data to a node (document works fine for this), and then in your extension, you can listen on document for this custom event type. Then in the event handler you'll have the URL.

But that's the easy part. The tricky part is that your content scripts won't be on the tab that you just installed from. If you have content scripts in your extension that load with every page load, they will only load with every page load after the install. So that page you installed from? You won't get the extension listening that page until you refresh it.

I can think of a number of solutions for this, and none of them are great. First, if on your partner sites they don't mind you screwing with the URL, you could add a hash (assuming there's no hash already) with a flag signifying that your extension just got installed. Then you can use the chrome extension tabs API to find the URL for the currently active tab in the currently active window. Reading that on load of your extension, if it has a has of say "#extensionInstallId=", then you could assume that this extension just got installed from that URL and record it. This isn't foolproof because if the person leaves that tab open, when they re-open the browser you'll get a false positive and get 2 install events when there was only one. I suppose you could even store a flag in localStorage for the extension and check that to see if it's really first install.

Second is to do something like this. That's messy because it will create a new popup window (just for the sole purpose of sending this event to your extension).

Community
  • 1
  • 1
Scott
  • 954
  • 1
  • 8
  • 15