扩展应该隐藏Netflix电影的视频播放器,但在执行后没有任何效果。var hidePlayer 的代码可以在 f12 工具中执行,则可以成功隐藏视频播放器。
内容.js
console.log("hi");
manifest.json
{
"name": "Hello World",
"version": "1.0.0",
"description": "Simple Microsoft Edge Extension",
"author": "Hrishikesh Kale",
"icons": {
"16": "icons/icon_16.png",
"32": "icons/icon_32.png",
"48": "icons/icon_48.png",
"128": "icons/icon_128.png"
},
"browser_action": {
"default_icon": {
"20": "icons/icon_20.png",
"25": "icons/icon_25.png",
"30": "icons/icon_30.png",
"40": "icons/icon_40.png"
},
"default_title": "Hello World"
},
"permissions": [
"contextMenus",
"tabs",
"storage",
"activeTab",
"<all_urls>"
],
"minimum_edge_version": "37.14316.1000.0",
"background": {
"page": "background.html",
"persistent": true
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"css" : ["css/light.css"],
"js": ["js/content.js"],
"run_at": "document_end"
}]
}
背景.js
browser.browserAction.onClicked.addListener(function(tab) {
var hidePlayer = "(function () { "
+" var panel = document.getElementById('appMountPoint');"
+" if (typeof (panel) != 'undefined' && panel != null) {"
+" if (panel.style.display === 'none') {"
+" panel.style.display = 'block';"
+" } else {"
+" panel.style.display = 'none';"
+" }"
+" }"
+"})();";
browser.tabs.executeScript({
code: hidePlayer
});
});
背景.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="js/background.js"></script>
</head>
<body>
</body>
</html>
我在这里附上了该项目。要重现该错误,请在加载扩展程序之前在 Edge 浏览器中播放 Netflix 电影。
在测试您的代码时,我发现 Edge 的操作是间歇性的。"重新加载"扩展似乎不是 100% 有效。显示背景页有时会进入一种模式,在该模式下,Edge 会打开扩展程序背景页的窗口,但窗口为空。我最终删除了扩展并多次重新启动Edge。我的印象是 Edge 扩展支持还没有真正准备好迎接黄金时间(即它是有缺陷的,需要开发工作)。
我发现在使用background
scripts
条目而不是page
条目时,扩展的操作更加一致。奇怪的是,在使用script
条目后,返回到使用page
条目开始工作。
我将您的清单.json更改为以下内容:
{
"name": "Hello World",
"version": "1.0.0",
"description": "Simple Microsoft Edge Extension",
"author": "Hrishikesh Kale",
"icons": {
"16": "icons/icon_16.png",
"32": "icons/icon_32.png",
"48": "icons/icon_48.png",
"128": "icons/icon_128.png"
},
"browser_action": {
"default_icon": {
"20": "icons/icon_20.png",
"25": "icons/icon_25.png",
"30": "icons/icon_30.png",
"40": "icons/icon_40.png"
},
"default_title": "Hello World"
},
"permissions": [
"contextMenus",
"tabs",
"storage",
"activeTab",
"<all_urls>"
],
"minimum_edge_version": "37.14316.1000.0",
"background": {
"scripts": ["js/background.js"],
"persistent": true
},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["js/content.js"],
"run_at": "document_end"
}]
}