In this example, there is one bug in the simple background code that causes a “dead object” error. There is a second bug when a ‘load’ handler is uncommented. A full step-by-step replication is provided below.
Manifest:
{
"manifest_version": 2,
"name": "Bug1",
"version": "0.2",
"icons": {
"48": "icons/link-48.png"
},
"permissions": [
"activeTab",
"contextMenus",
"notifications"
],
"background": {
"scripts": ["PM_bg.js"]
}
}
PM_bg.js:
// S: Promise to show string in notification box
function S(Msg,Title)
{
return browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("icons/link-48.png"),
"title": Title,
"message": Msg});
} // S
S('bg running','Direct from bg').then(empty).catch(err);
/*
window.addEventListener('load',function(e)
{
S('bg loaded','Direct from bg').then(empty).catch(err);
}, true);
*/
// Functions
function empty(ignored)
{
console.log('doing nothing');
} // empty
function err(Msg)
{
console.log('*** '+Msg);
} // err
// End
Instructions:
-
Add Bug2 as a temporary extension.
-
Click about:debugging#addons > Debug link.
-
Click trash can in the debugger to clear out any errors by other extensions or Firefox bugs.
-
Ctrl+F5 to restart my background code.
-
Note “TypeError: can’t access dead object” error. Find what I’m doing to cause this.
-
Note that a “bg running” notification box appears. Close the debugger.
-
Go back in my code and remove the comment brackets around the call to window.addEventListener().
-
Click about:debugging#addons > Reload link.
-
Do steps 2-4 again.
-
Note this time that the notification box doesn’t appear. Find my bug that causes this.