Converting any Chrome extension to Edge (in theory)

By | March 19, 2016

We already established Edge extensions and Chrome extensions are very similar, so, with Edge extensions now available in build 14291, how exactly would one convert an existing Chrome extension to run in Edge? It’s hard to give a complete guide without official documentation (We’ll have to wait for Build to get that), but from digging through the demo extension provided by Microsoft I’m fairly confident the guide below is a pretty good start.

Porting extensions with a minimal amount of work is definitely possible, as demonstrated by F.B. Purity and the wonderful Tweeten. I’ve tried to port a couple of popular extensions myself, with mixed results, most likely because not all the planned extension APIs are included in this release.

I suggest you give the steps below a try yourself and leave a comment on your experience.

Step 1: Grabbing the Chrome extensions source

This one’s pretty easy and well documented all over the web. Every Chrome extension is identified by a unique ID, you can find the id of any installed extension in the Extensions window, or as part of the URL on the Chrome Web Store:

https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom

To download the .crx file that contains the extension code you simply replace ID_HERE in the following url:

https://clients2.google.com/service/update2/crx?response=redirect&prodversion=38.0&x=id%3DID_HERE%26installsource%3Dondemand%26uc

Step 2: Extracting the crx file

.crx files are actually just zip files (well, almost…), extract it using your favourite zip tool (rename it to .zip if necessary).

Step 3: Modifying manifest.json

By now you should have the source files of the extension you’re trying to convert, let’s start the actual modifications. The manifest file only needs one additional key:

"minimum_edge_version": "33.14281.1000.0"

If your app uses localization it looks like you’ll need to add one other key, “locale“. Chrome uses a “default_locale” key, but going by the example extensions provided by Microsoft Edge uses this additional key. So if there’s a “default_locale” key present in manifest.json you’d better add a “locale” key with the same value.

Step 4: Modifying the javascript

This is probably the most important step, Chrome’s APIs are accessed through the chrome.* object, judging by the extensions provided by Microsoft, Edge uses either msBrowser.* or browser.*, you could go and replace all occurences of chrome with msBrowser, but the easy (and more complete) way to handle this is to insert this piece of code (pulled directly from Microsoft’s code) in any file that uses Chrome’s APIs:

if (typeof msBrowser !== 'undefined') {
 chrome = msBrowser;
}
else if (typeof browser != 'undefined')
{
 chrome = browser;
}

This should make Edge’s APIs accessible through the chrome object.

Step 5: Perform some permission magic

The extension should run in Edge now, but when you actually try and load the extension you’ll receive this super helpful error:

Edge-Error

This one took me quite a while to figure out actually, the Learn More link suggests it’s a permissions problem, and suggests running the install script again. After some digging through said installer I found that among the code to extract the extension to the downloads folder, there’s a single line that modifies the Acces Control List for the newly created directory: Edge-permissions

To get your extension running in Edge you’ll need to set the same permissions for the folder you’re using, simply download or create a .cmd file with this line and run it from inside the directory you want to set permissions on:

icacls %CD% /grant "*S-1-15-2-3624051433-2125758914-1423191267-1740899205-1073925389-3782572162-737981194":"(OI)(CI)(WDAC,WO,GE)"

Loading the extension in Edge should work now.

Be sure to share your experiences by leaving a comment below!

  • Quinten Johnson

    There’s a typo in your code I think, the first line should read “!=” not “!==”

  • http://forum.winpoin.com/user-jazz Jazz

    which files should be modify in step 4?

    • http://bav0.com BAV0

      Any javascript code that references chrome.*, could be a .js file or a tag inside a .html file

      • http://forum.winpoin.com/user-jazz Jazz

        Just got same error, (do step 4 on adblock_start_chrome.js, fix permission)
        in the end this just ‘theory’, isn’t it? :)

  • http://www.ofaolain.com David Whelan

    This was really helpful, thank you. I also had to make changes to the background element in the manifest.json (“persistent”:true) and to add an author. I suppose some of these will pop up based on how well the original Chrome extension was populated with the defaults Edge is expecting. Thanks again for your post.

  • Michael Read

    Hi!! I used the info here to check out the Microsoft edge extension toolkit, I am a complete novice but even with my very limited ability was able to convert and load a Chrome extension into Edge, most of it worked but I was not able to fully complete the conversion, sure some of you people could though.