Javascript Microsoft边缘扩展选项卡内容

Javascript Microsoft边缘扩展选项卡内容,javascript,browser,microsoft-edge,microsoft-edge-extension,Javascript,Browser,Microsoft Edge,Microsoft Edge Extension,我正在探索微软边缘扩展的开发。基本上,我是在尝试读取选项卡的HTML内容。下面是我的解决方案中的代码片段 我的manifest.json如下所示 { "name" : "HTML Reader", "version" : "1.0.0.0", "author" : "Stack Memory", "browser_action" : { "default_icon" : { "20" : "ico

我正在探索微软边缘扩展的开发。基本上,我是在尝试读取选项卡的HTML内容。下面是我的解决方案中的代码片段

我的manifest.json如下所示

{
    "name" : "HTML Reader",
    "version" : "1.0.0.0",
    "author" : "Stack Memory",
    "browser_action" : 
    {
        "default_icon" : 
        {
            "20" : "icon_20.png",
            "40" : "icon_40.png"
        },
        "default_title" : "Sample extension",
        "default_popup" : "index.html"
    },
    "content_scripts" : [{
            "js" : ["js/index.js"],
            "matches" : ["*://*/*"]
        }
    ],

    "content_security_policy" : "script-src 'self'; object-src 'self'",
    "default_locale" : "en",
    "description" : "This is a sample extension that illustrates the JSON manifest schema",

    "permissions" : 
    [
        "*://*/*", "notifications", "cookies", "tabs", "storage", "contextMenus", "background"
    ],
    "icons" : {
        "128" : "icon_128.png",
        "16" : "icon_16.png",
        "48" : "icon_48.png"
    },
    "minimum_edge_version" : "33.14281.1000.0",
    "web_accessible_resources" : ["icon_48.png"]
} 
我的
index.js
如下所示

function getDomObject(tab) {
    browser.tabs.sendMessage(tab.id, {
        method: 'getDomContent'
    },function(response) {
        if (browser.runtime.lastError) {
            console.log("Error: ", browser.runtime.lastError);
        } else {
            alert(response.innerText);
        }
    });
}

function onCodeCall(){
    browser.tabs.query({currentWindow: true, active: true}, function(tabs){
        var tab = tabs[0];
        getDomObject(tab);
    });
}
单击扩展按钮后运行函数
oncodel

我没有得到任何错误,我的回调函数也没有命中。这段代码在Chrome中运行良好,但在Edge中失败

任何帮助都将不胜感激。
谢谢。

选项卡。sendMessage
只能在扩展上下文中调用,例如后台页面。但是,您在内容脚本中调用它,无论是在Microsoft Edge还是在Chrome中,这显然都不起作用。

选项卡。sendMessage只能在扩展上下文中调用,例如后台页面。但是,您在内容脚本中调用它,这显然不起作用,无论是在Microsoft Edge还是在Chrome中。

您能否提供一个简单的示例,包括
manifest.json
background.js
content.js
?您正在
background.js
中调用上述方法,对吗?请提供一个简单的示例,包括
manifest.json
background.js
content.js
?您正在
background.js
中调用上述方法,对吗?