This is an initial prototype that demonstrates how to populate the sidebar
with content when it loads, and how to refresh the content as needed by
handling the tabs.onActivated and tabs.onUpdated events.
It also illustrates how the communication works between the panel.js script
that keeps track of whether the sidebar is open or closed using a boolean
variable in the background script named sidebarIsOpen, and the
browserAction.onClicked event listener in background.js that utilizes that
variable to implement the sidebar toggling behavior.
It includes the following features:
- Browser action button for the extension toggles the sidebar open or closed.
- The sidebar displays the URL of the active tab in its content area by using
the
tabsAPI. - The URL is updated when the active tab changes or a new page is loaded.
- It does not utilize a content script, so the messaging is very basic.
Notes:
- Based on the Mozilla
webextensions-examplesrepoannotate-pageexample:- Removed event handlers that add and remove the
contenteditableattribute. - Removed functionality that stores annotations.
- Removed event handlers that add and remove the
This prototype builds on the feature set of the sidebar prototype by adding
the following new features:
- Utilizes a content script to get information from the page loaded into the active tab (currently, just the page title and URL).
- The message passing within the extension now does the following:
- When the sidebar content needs to be updated, the
getContentfunction is called, which runs the content script. - It, in turn, sends a message, which
panel.jslistens for. - When that message is received, it contains the content needed for the call
to the
updateSidebarfunction.
- When the sidebar content needs to be updated, the
- The prototype uses the
browser.i18nAPI to store and retrieve UI labels and messages from locale-specific files.
This prototype builds on the feature set of the content-script prototype by
adding the following new features:
- The content script traverses the DOM of the page loaded into the active tab and saves filtered information (currently only heading elements) into the data structure that it sends as a message to the background script.
- The content script uses the DOM
TreeWalkerAPI. - The message passing is now centralized, and occurs only between the content
and background scripts. When the background script receives the message, it
stores its data in the
contentInfovariable. - The function
updateContentinpanel.jscalls the content script, and waits until the Promise it receives acknowledges that the script has executed before it accesses the data stored in the background script'scontentInfovariable. - The event listeners for tabs.onUpdated and tabs.onActivated are removed when the sidebar is closed.
- The tabs.onUpdated event listener now has a filter that specifies that only
updates to the
statusproperty should fire events. - A special handler for tabs.onUpdated events, named
handleTabUpdate, was created that examines thestatusproperty: When its value is "complete" it calls theupdateContentfunction; otherwise it displays thetabIsLoadingmessage using a timeout to avoid jerkiness with sidebar content updates. - Missing from previous prototypes was an
onFocusChangedhandler, which has now been added inpanel.js. This handles the situation when a link is opened in a new window. It is interesting to note that the sidebar will always display the same information when there is more than one window, i.e. the information for the active tab, even if it's in a different window.
The headings-* prototypes build on the feature set of the traversal
prototype.
- The sidebar now displays headings information for the active tab in a box
labeled
Headings, using CSS grid layout features. Each heading item has a prefix label indicating its level, and is indented horizontally based on its level. - The items in the
Headingsbox are scrollable, and each item is selectable. - There are two buttons below the
Headingsbox, one labeledHighlight Selectedand the otherRemove Highlighting, each with its own event handler. - The handler functions for the highlight buttons use the
browser.findAPI, which only partially works in production Firefox, and is throwing errors in FDE whenbrowser.find.highlightResultsis called. In the former case, the call does not result in scrolling to the highlighted results. - Messaging now takes place directly between
content.jsandpanel.js, so thecontentInfovariable inbackground.jswas removed. - When the
panel.jsfunctionupdateContentis called, it executes the content script. ItsonExecutedcallback only logs caller information, as thepanel.jsscript now waits for the message fromcontent.jsbefore calling theupdateSidebarfunction with the heading information contained in the message. - The content script functions have been rewritten: The
getInfofunction now includes a nested function namedtraverseDomthat uses theDOMAPI directly, replacing the use of theTreeWalkerAPI. Another new function,getDescendantTextContent, recursively handles the collection of text content for each heading.
The structure-* prototypes build on the feature set created in the series of
headings-* prototypes.
-
structure-1
- Adds the
listbox.jsscript and its companionlistbox.cssto encapsulate the functionality of the headings list.
- Adds the
-
structure-2
- Refactored to utilize ES6
moduleswherever possible. - The
listbox.jsscript was converted to a JavaScript class that is the default export of the module. - Reworked DOM traversal to include
custom elements(by examining theshadow rootchildren) and anyslotelements they may contain. - The
content.jsscript was split into two scripts with the addition oftraversal.js. - The
storage.jsscript was added as a facility for future versions if and when extension options / preferences are needed.
- Refactored to utilize ES6
-
structure-3
- Reworked the messaging scheme to use a persistent port for communication
between the
panel.jsandcontent.jsscripts. - Although not yet displayed in the sidebar, includes collecting information on landmarks as well as headings.
- Refactored the
traversal.jsscript such that the DOM traversal function is greatly simplified. It now relies on a new function namedsaveInfo. - After adding the function
testForLandmark, thetraversal.jswas split into two scripts, moving utility code intoutils.js
- Reworked the messaging scheme to use a persistent port for communication
between the
-
structure-4
- Modified the
getStructureInfofunction to handle HTML documents that omit theBODYtag. In such cases, it starts the DOM traversal at thedocument.documentElementelement (usually theHTMLelement). - Added the
isSkippablefunction to skipmetatags such asSCRIPTandSTYLEwhen traversing the DOM. - Reworked console logging in
panel.jsto use thelogToConsolefunction, which callsconsole.debuginstead ofconsole.log. - Added the ability to keep track of the landmarks hierarchy, i.e. all of
the ancestor / descendant relationships, by adding a tree data structure
in the
infoobject used bygetStructureInfo. The tree object is built with objects returned by thegetLandmarkNodefunction. - Added the
logLandmarkNodesfunction to display (in the console) the new landmarks hierarchy of ancestor / descendant relationships.
- Modified the