Я понимаю, как запустить отладчик расширений, но не могу понять сообщения об ошибках.Я думаю, что я сделаю, это опубликовать весь мой код, несмотря на то, что он есть, и надеюсь, что кто-то может помочь.Я опытный программист, но WebExtensions кажется очень сложным для изучения.До сих пор я потратил несколько дней, пробуя примеры (которые работают) и создавая свой собственный код (который в основном не работает).
Комментарии объясняют, что я пытаюсь сделать, что в основном пытаетсясоздать фоновую и переднюю среду, в которой, в конце концов, будет создан менеджер паролей.
manifest.json:
{
"manifest_version": 2,
"name": "PwdMgr",
"description": "User tool to manage passwords and log into websites.",
"version": "0.2",
"icons": {
"48": "icons/link-48.png"
},
"permissions": [
"<all_urls>",
"activeTab",
"contextMenus",
"notifications"
],
"background": {
"scripts": ["PM_bg.js"]
}
}
PM_bg.js:
// 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);
// Receive and show fg msgs
browser.runtime.onMessage.addListener(function(message)
{
if (message.msg)
S(message.msg,'Msg from fg').then(empty).catch(err);
if (message.clickmsg)
S(message.clickmsg,'Click Msg from fg').then(empty).catch(err);
});
// Create context menu item
browser.contextMenus.removeAll().then(p2).catch(err);
function p2()
{
browser.contextMenus.create(
{
id: "ServInt",
title: "ServInt Reports"
}, function()
{
if (browser.runtime.lastError)
err(browser.runtime.lastError);
}); // Sync
} // p2
// Create context menu command to run PM_fg.js
browser.contextMenus.onClicked.addListener(function(info, tab)
{
if (info.menuItemId == "ServInt")
{
var p=browser.tabs.executeScript({file:"/PM_fg.js"}).then(fgReady).catch(err);
}
}).then(empty).catch(err);
// FG is ready
function fgReady(Result)
{
S('browser.tabs.executeScript is done; FG is running','msg from BG').then(empty).catch(err);
// Send message to fg
//browser.runtime.sendMessage({"msg":"from background"});
} // fgReady
// BG unloading: delete context menu item
window.addEventListener('unload',function(e)
{
// This is never run!
browser.menus.removeAll().then(empty).catch(err);
S('removed menu items','Direct from bg').then(empty).catch(err);
console.log('removed menu items');
});
/*
//var gettingCurrent = browser.tabs.getCurrent()
browser.tabs.sendMessage(
0,
{msg:"from background"}).then();
*/
// Functions
function p1()
{
console.log('Notification done (bg)');
} // p1
function empty(ignored)
{
console.log('doing nothing');
} // empty
function err(Msg)
{
console.log('*** '+Msg);
throw Msg;
} // err
// End
PM_fg.js:
// has access to active tab when context menu item is selected:
// Tab.url, Tab.title, and Tab.faviconUrl
// S: Show string in notification box
// by sending msg to bg
function S(Msg)
{
browser.runtime.sendMessage({"msg":Msg}).then(empty).catch(err);
} // S
S('fg running');
// Receive message from bg
function MsgFromBg(message)
{
}
browser.runtime.onMessage.addListener(MsgFromBg);
/*
// On click send a message to bg
function OnClick(e)
{browser.runtime.sendMessage({"clickmsg":"from fg click"});}
window.addEventListener("click",OnClick);
*/
// Functions
function empty(ignored)
{
console.log('doing nothing - fg');
} // empty
function err(Msg)
{
console.log('fg*** '+Msg);
} // err
// End