The browser extension framework
View the Project on GitHub exteranto/exteranto.github.io
Getting Startedmanifest.json
(FF, CHR)
is the only required file for an extension. The main purposes of the manifest
are as follows:
name
, version
, locale
etc.background
, content_scripts
, devtools_page
,
options
and bundled web_accessible_resources
storage
, tabs
, bookmarks
, https://*/*
browser_action
iconContent (FF, CHR):
Depending on the correct permissions being specified in manifest.json
(both
under permissions
and under content_scripts.*.matches
fields), the content
scripts (.js
or .css
) are loaded into and executed within the context of a
given web page. They have access to the DOM and as such can read and manipulate
the existing HTML. These scripts can dispatch XHRs. In order to interact with
most other browser APIs/resources or with other extension elements (e.g. to tell
them about certain DOM elements present) they must usually communicate via the
intermediary of a background script
, through message passing (see below). In
order to communicate with a page <script>
(or vice-versa) the
window.postMessage()
API must be used.
Note: content script loading is limited to a specified url e.g.
https://www.example.com
, but we can widen the permission using wildcards, as inhttps://*/*
Background (FF, CHR):
The background script(s) (.js
, or a single .html
background page) are loaded
into and executed within the browser environment. They access most of the
browser APIs (depending on their permissions as specified in manifest.json
)
and can listen to browser events etc. Background scripts tend either to run for
an extended duration in order to maintain state or to serve as a semi-dormant
event handler. They are provided their own window
for DOM access (with
limitations) and can dispatch XHRs. The background scripts cannot interact
directly with a loaded webpage, but must act via a content script that they load
into that page context. This communication is via asynchronous ‘message passing’
with either side registering message listeners to trigger actions on receipt
(FF, CHR).
.html
popup may be specified in the manifestdevtools.html
script must be registered)During development, the extension can be loaded from a local folder or file (in case of Firefox) for testing. The process is very similar for Chrome and Firefox.
chrome://extensions/
about:addons