Calling webpage JavaScript methods from browser extension

Your content script is in a different context/scope from that of page scripts (scripts that already exist in the webpage). Your content script has higher privileges than are granted to page scripts. Keeping content scripts separate from page scripts is a normal architecture for browser extensions, which is done for security reasons. Because your content … Read more

TypeError: [API] is undefined in content script or Why can’t I do this in a content script?

Content scripts do not have access the API you are using You are attempting to do this from a content script. You need to be doing this from a background script. Content scripts have access to a small subset of the WebExtensions APIs. The available APIs include (from the MDN Content Scripts page): From extension: … Read more

Firefox extension .xpi file structure: description, contents, creation, and installation

.xpi file format (Extension Packaging) The .xpi files that are used as containers for Mozilla (Firefox, Thunderbird, etc.) extensions are merely zip archives that have had the file extension changed to .xpi with the files added to the archive using either “deflate” compression, or uncompressed. If you use any other type of compression, other than … Read more

Communicate between scripts in the background context (background script, browser action, page action, options page, etc.)

Communicating with a page in the background context Pages which are open in the background context include: background pages/scripts(MDN) event pages (Firefox does not support event pages. All manifest.json background pages remain loaded at all times.) browser action popups(MDN) page action popups(MDN) options pages(MDN1, MDN2) (in a popup, a tab, or window) sidebar action pages … Read more

How to open the correct devtools console to see output from an extension script?

Your code is correct as written, it works and outputs to console. If you are not seeing it, then you are, probably, looking at the wrong console. 1. Firefox Mozilla describes what extension output can be seen in which console in their Debugging article. Browser Console The Browser Console no longer shows output from WebExtensions … Read more

onclick or inline script isn’t working in extension

Chrome Extensions don’t allow you to have inline JavaScript (documentation). The same goes for Firefox WebExtensions (documentation). You are going to have to do something similar to this: Assign an ID to the link (<a onClick=hellYeah(“xxx”)> becomes <a id=”link”>), and use addEventListener to bind the event. Put the following in your popup.js file: document.addEventListener(‘DOMContentLoaded’, function() … Read more