0

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.

Brian
  • 25,523
  • 18
  • 82
  • 173

3 Answers3

2

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
PAEz
  • 8,366
  • 2
  • 34
  • 27
  • Packing the extension at install time comes close to being a good solution but unfortunately it would wreck automatic updates unless I include a PEM. Mucking with the policy method is also clever but my users will be angry if Chrome uninstall fails. That being said, I could packing an extension myself as part of the install process and have that extension communicate with the main extension somehow. Not ideal, but I'll accept this as an answer if nobody can suggest something better. – Brian Mar 13 '12 at 13:39
  • Yeah, I thought of the second extension idea aswell but thought maybe its a little messy. If you do then the main extension could just accesse a page in the second extension that you generate in the installer. Just load it in an iframe and have it post a message to the main extension/parent frame with your info, like I did here..... http://stackoverflow.com/questions/9033873/options-enabled-content-script-chrome-extension-without-background-page ...then maybe clean up with Management... http://code.google.com/chrome/extensions/management.html#method-uninstall ..seems excessive tho aye? ;) – PAEz Mar 13 '12 at 16:09
  • The problem vanished on its own due to specification changes, but this is probably the solution I would have used. – Brian Mar 17 '12 at 00:06
0

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.

Alejandro Silvestri
  • 3,706
  • 31
  • 43
  • Is there any chance you could make a small example of using cookies as I dont have any experience with cookies and am very interested in this method. – PAEz Mar 13 '12 at 10:59
  • This solution would definitely work, but I don't want my installer to launch Chrome (or at least, not in a user-visible way). – Brian Mar 13 '12 at 13:44
0

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.

Yosi
  • 2,936
  • 7
  • 39
  • 64