Importing a JS lib and calling it's functions?

Hi *,

I’m new to Addons and not to familiar with JS but I manedged to get a basic addon running. Now what I would like to do is import the openpgp.min.js and then call some of it’s functions to enc/dec.

So far I have tried loading the script into my main.js file which I can’t seem to call annt then I added it into the manifest.json at the section ‘content_scripts -> js section’.

So far I have been testing things in my Console but I got the feeling that I cannot access the scope of addons via the console. Can I?

This leads me to belive that the addons properties and methods can’t be called from the console so if that is the case? Is there some tool/s in which I can develope an addon but can also test it by calling methods and vars in a console?


Stuff’s hard :smiley:.
Content scripts are indeed not accessible through developer console - unless you are debugging! At least that’s my experience.

So when I need to test something in my content script at runtime, I just put a breakpoint somewhere and when it stops there, I can execute and access things available in current context (more or less). The good news is, in Firefox you can even call asynchronous API and it will resolve (even with stopped debugger), which doesn’t seems to work in Chrome.

Other contexts like background page or extension pages can be accessed through console even without debugger (if I remember correctly), but only if you are not loading your JavaScript as a module:

<script type="module" src="main.js"></script>

But in that case, you can still call “import” function from the console to get access to your modules.

To expand on that, shows how to get a console with the respective context for all the various places extensions can execute code.

As to how to importing a lib and using it vastly depends on the lib and the kind of scaffolding you’re looking for.