Firefox 扩展 - 如何从后台脚本向用户显示文本?

Firefox extension - How to show text to user from background script?

这可能是一个很基础的问题,但我在网上找不到答案。我正在尝试做的是在单击上下文菜单项后向用户显示一些文本。我首先考虑使用 alert() 但后来意识到,这在后台脚本中是不可能的。有没有其他方法可以向用户显示一些文本?任何想法将不胜感激。

我的 background.js 文件:

browser.contextMenus.create({
    id: "showtext",
    title: "Show text",
    contexts: ["selection"]
});

browser.contextMenus.onClicked.addListener(function (info, tab) {
    switch (info.menuItemId) {
        case "showtext":
            {
                console.log(info.selectionText);
                // alert() doesn't work here
                // looking for alternative
            }
    }
});

仅供参考:我正在尝试创建一个小的加密和解密工具。

PS:我是扩展的初学者。 :(

您可以在页面中插入元素:

const node = document.createElement('div');
node.textContent = "This page has been eaten";
document.body.appendChild(node);

根据需要设置样式,使其按您需要的方式显示。

MDN:https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Modify_a_web_page

对于以后发现这个问题的大家:

我最终打开了一个新标签,运行其中有一个脚本:

browser.tabs.create({ url: "/pages/mypage.html" }).then(() => {
    browser.tabs.executeScript({
        code: "alert(`" + mytext + "`);"
    });
});

PS: 我没有使用alert,这只是一个例子。