You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 06:20:23