How to install browser extension from my program
-
13-06-2021 - |
Question
I want to bundle an extension with my executable, and I want it to automatically add it to the users browser if they have chrome or firefox. Is there a directory where I can drop the .crx file containing the extension for chrome, and chrome will automatically use it? And what should I do for firefox?
Solution
For Chrome:
You can put it in the registry or drop it in the external-extensions.json file (%localappdata%/Google/Chrome/Application/chrome_xx.xxx.xxx.xxx/Extensions/
).
I never did it myself actually but it's all documented on the official channel: http://code.google.com/chrome/extensions/external_extensions.html
There's also a way to install it via Group-Policy, but none of all these three methods is cross-platform AFAIK.
For Firefox:
I have no idea.
OTHER TIPS
If you want to simplify things you can use Crossrider and get an installer which will install your extension on IE, Firefox and Chrome. This installer can also run in silent mode, so you run it from your executable without interrupting the normal flow. To do all that, you will first have to open a new user and copy your extension code to Crossrider (which is probably a good idea anyway since then you will have one code for your app which will support all browsers).
My recommendation would be:
- DO go through the browser itself,
- DO NOT try to sneak around and force it onto the user
Reasons for this are:
- the browser is meant to ask for the user's permission, clearly and explicitly.
- that's the only cross-platform way I know (and it already requires forking out, so that's not even that totally cross-platform).
I'd simply recommend forking out a browser and passing as argument the extension's file or download URL, so that it will automatically request the user's permission and start the installation process.
For instance, just calling this (on linux, if google-chrome
is on your PATH
):
google-chrome PATH_TO_FOLDER_OR_URL_PREFIX/myextension.xpi
Or:
google-chrome PATH_TO_FOLDER_OR_URL_PREFIX/myextension.crx
Or for Firefox:
firefox PATH_TO_FOLDER_OR_URL_PREFIX/myextension.xpi