Firefox扩展无法按预期打开新标签页问题求助
Firefox版浏览器扩展无法通过上下文菜单打开词典标签页
我开发了一款浏览器扩展,支持选中文字后打开在线词典页面查询翻译。Chrome版本运行正常,但Firefox版本点击上下文菜单的「在词典中查找单词」选项时,无法打开新标签页加载词典页面。
Firefox版本background.js代码
chrome.contextMenus.create({ id: "1", title: "Najít \"%s\" ve slovníku", contexts: ["selection"], onclick: openTab(), }); function openTab() { return function (info, tab) { let text = info.selectionText; let dicLink = "https://slovnik.seznam.cz/preklad/nemecky_cesky/" + text chrome.tabs.create({ index: tab.index + 1, url: dicLink, selected: true }); } };
Chrome版本background.js代码
chrome.contextMenus.create({ id: "1", title: "Najít \"%s\" ve slovníku", contexts: ["selection"], }); chrome.contextMenus.onClicked.addListener( openTab() ) //opens tab and give selected text into german to czech dictionary function openTab() { return function (info, tab) { let text = info.selectionText; let dicLink = "https://slovnik.seznam.cz/preklad/nemecky_cesky/" + text chrome.tabs.create({ index: tab.index, url: dicLink, selected: true }); } };
Chrome的manifest配置
{ "manifest_version": 3, "name": "Německý Seznam slovník vyhledáváč", "version": "1.0", "description": "Otevře německý slovník od Seznamu.", "permissions": [ "contextMenus" ], "background": { "service_worker": "js/background.js" }, "browser_action": { "default_icon": "images/icon2.png" }, "icons": { "16": "images/icon2.png", "32": "images/icon2.png", "48": "images/icon2.png", "128": "images/icon2.png" } }
Firefox的manifest配置
{ "manifest_version": 2, "name": "Seznam-slovnik vyhledavac", "version": "1.0", "description": "Otevře německý slovník od Seznamu.", "permissions": [ "contextMenus", "tabs" ], "background": { "scripts": [ "js/background.js" ] }, "browser_action": { "default_icon": "images/icon2.png" }, "icons": { "16": "images/icon2.png", "32": "images/icon2.png", "48": "images/icon2.png", "128": "images/icon2.png" } }
Chrome扩展使用ManifestV3,Firefox扩展使用ManifestV2(因Firefox暂不支持ManifestV3)。原以为Chrome代码能兼容Firefox,但找不到问题所在,特此求助。
内容的提问来源于stack exchange,提问作者LEXA
相关产品推荐
相关产品推荐

