Brian
Brian

Reputation: 25834

Making a Windows Installer communicate with a Chrome extension without NPAPI

I have a windows application which installs a Chrome extension via the windows registry. I wish for this application to generate some one-time information for Chrome to read based on information typed in by the user during the installation process.

Assuming I am not using NPAPI in the Chrome extension, is there anywhere the installer can place information such that the extension will see it?

Edit: I also wish to launching chrome at the end of the installation.

Upvotes: 0

Views: 589

Answers (3)

Yosi
Yosi

Reputation: 2976

Instead of communicating through the windows registry, you can create a WebSQL from the installer and from the extension read the data from there.

You will need to a bit of research about how to this, but this is possible. the steps should be:

  1. The installer will create the database and register to chrome (maybe with the Databases.db)
  2. The extension will use openDatabase to create a connection to the database
  3. The extension will do a transaction and read the needed file.

Another option is to add file to the crx for example "installer_info.json" and do an AJAX request from the extension to the "installer_info.json" file.

There is no formal way for doing this things, little research and you will have a way.

Upvotes: 0

PAEz
PAEz

Reputation: 8542

Another way you can pass information to an installed extension from outside of Chrome is to have a page with your extension that you then open Chrome too and pass the info in the hash...such as....

chrome.exe "chrome-extension://emcggffhhapbbkcodabdliakappfibcf/showHash.html#info"

Problem with this method is your installing the extension using the simple registry method (Im guessing) and not using the Policy method. With the Policy method you can force an install and it will happen even if Chrome is allready open (where as according to the docs the simple method happens the next time Chrome is opened). Downside to this is you will have to make an uninstaller yourself as you cant uninstall an extension from Chrome that is installed with this method. Im also not sure how quick/often it will be before the extension is installed (couldnt find it in the docs and too lazy to try it ;)) and youd need to make your installer wait a bit for it to be installed....
http://www.chromium.org/developers/how-tos/adding-new-policies
http://dev.chromium.org/administrators/policy-list-3#ExtensionInstallForcelist
http://dev.chromium.org/administrators/policy-templates (says where in the registry to add them)

Another possible method could be to pack the extension at install time and add a file with the info that the extension could read. Problem with this method is that the extensions ID would change (might not be a problem for you?) or youll have to include the PEM in your installer which you probably dont want to do....

chrome.exe  --pack-extension="C:\simple-example" --no-message-box

Upvotes: 2

Alejandro Silvestri
Alejandro Silvestri

Reputation: 3774

Many people wish there were an event firing on extension installing.

There's a workaround, not elegant way to send info to the browser from outside: launch chrome asking to open an url.

I use it with a local html file. My application execute a command line like:

"pathToChrome\Chrome.exe" "file://pathToHtmlFile/myFile.html?param1=value1&param2=value2"

The info I pass are the page's parameters.

The catch is that this page is read by the extensions in one of many ways:

  • You can write a content script this page will fire
  • You can put some javascript on this page to write down the parameters as cookies, for the extension to read in the future (without calling the extension at this time)

It hasn't to be a local page. If your page is on a server, it can save the parameters in the server, ir it worthy.

It hasn't to be even your page. You can call any page on Internet, but beeing sure it will fire your content script extension, and it will read your "customized" parameters.

Upvotes: 0

Related Questions