Hello,
I’m building a web extension that allows you to select a base64 certificate text and it will spit out all the useful data inside it. The heavy lifting is done by forge.
I added 2 scripts in my manifest: background script and forge script. Forge seems to load first. In theory any global object defined by the first script can be seen by the second one. I should be able to see the forge object from my background script but this is not true.
Here is an unlisted version so you can test it out. I basically get undefined for forge in background.js.
In order to reproduce the issue, install the extension, open an about:debugging page and start debugging “Base64 Certificate Viewer”, then open this page or any other certificate, select all the text, right click and call the menu action to view. The console of the debugger will show this error.
So the import thing worked for my extension but broke the karma unit tests. I came up with this ugly hack: have a file that loads only in manifest.json but not in karma tests . This file loads the forge library with import from and sets it on the window object. It’s kind of ugly but it works both in browser and in tests https://github.com/andreicristianpetcu/Base64CertificateViewer/blob/master/app/scripts/linker.js
I use import ... from ... at many places in my add-on and it passes validation. The thing is that once you have processed your files with webpack, the import should have been resolved and you should be left with a single, bigger background.js which should include both the original background.js plus forge, and it should not contain import any more. Are you sure you are not submitting a source code in the add-on you validate ?
import is not supported in all Firefox versions, and potentially behind a pref flip. So if you want import, you need that pref flip. I also think you need webpack to use that library.
Does any of you have a gulp + webpack project I can shamesly copy/paste configs from?
My add-on, Video DownloadHelper uses gulp and webpack. Through the code is not open-source, the build mechanism is based on the weh toolkit under MPL license. Hope this helps.