【发布时间】:2017-01-12 05:01:40
【问题描述】:
我正在探索 Microsoft Edge 扩展开发。基本上我正在尝试阅读选项卡的 HTML 内容。下面是我的解决方案中的代码 sn-p。
我的 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);
});
}
函数onCodeCall在点击扩展按钮时运行。
我没有收到任何错误,而且我的回调函数也没有命中。此代码在 Chrome 中运行良好,但在 Edge 中失败。
任何帮助将不胜感激。 谢谢。
【问题讨论】:
-
能否提供一个简单的示例,包括
manifest.json、background.js和content.js?而你在background.js中调用了上述方法,对吧?
标签: javascript browser microsoft-edge microsoft-edge-extension