我的后台Webextensions代码中出现了一些错误,调试器没有清楚地报告该错误。
首先,如果使用以下代码,则会收到预期的通知:
// S: Promise to show string in notification box
function S(Msg,Title)
{
var p=browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("icons/link-48.png"),
"title": Title,
"message": Msg});
return p;
} // S
S('bg running','Direct from bg').then(empty).catch(err);
// Functions
function empty(ignored)
{
console.log('doing nothing');
} // empty
function err(Msg)
{
console.log('*** '+Msg);
} // err
但是...如果我添加以下代码:
window.addEventListener('load',function(e)
{
S('bg loaded','Direct from bg').then(empty).catch(err);
}, true);
然后这两个通知都不会发生,而且我收到的奇怪错误消息在我的文件之外的文件中因试用而异,例如有关“死对象”的错误,无论它们是什么。
我的猜测是我使用Promises错误,因为这是我第一次使用它们。我已经研究了一些教程,并且我认为我理解它们,但是我可以在这里使用一些帮助。
已添加:
以下是一些示例错误消息:
Error: Could not establish connection. Receiving end does not exist. bg.js:106:5
TypeError: can't access dead object[Learn More] accessible.js:142:5
Error: Could not establish connection. Receiving end does not exist. bg.js:106:5
null has no properties background.js:1
Error: Could not establish connection. Receiving end does not exist. bg.js:106:5
TypeError: Argument 1 of PrecompiledScript.executeInGlobal is not an object.[Learn More] ExtensionContent.jsm:497:18
null has no properties background.js:1
Error: Could not establish connection. Receiving end does not exist. bg.js:106:5
doing nothing PM_bg.js:23:2
Error: Could not establish connection. Receiving end does not exist. bg.js:106:5
同样,所有带错误的文件名都不属于我自己。我的背景文件是PM_bg.js,它仅生成“什么都不做”。
已添加:
没有人在回应。你需要我的清单吗?在这里:
{
"manifest_version": 2,
"name": "Bug1",
"version": "0.2",
"icons": {
"48": "icons/link-48.png"
},
"permissions": [
"activeTab",
"contextMenus",
"notifications"
],
"background": {
"scripts": ["PM_bg.js"]
}
}