Javascript 为什么不是';我的边缘扩展中的内容脚本块是否正常工作?
我为Chrome和Firefox提供了一个有效的扩展,我也尝试在MicrosoftEdge中使用它。由于某种原因,内容脚本停留在“runtime.sendMessage”函数上。我使用了Edge 40.15063 Edge控制台显示: “API调用:'runtime.sendMessage'” “脚本块(9)(214,17)。” manifest.json:Javascript 为什么不是';我的边缘扩展中的内容脚本块是否正常工作?,javascript,json,microsoft-edge,microsoft-edge-extension,Javascript,Json,Microsoft Edge,Microsoft Edge Extension,我为Chrome和Firefox提供了一个有效的扩展,我也尝试在MicrosoftEdge中使用它。由于某种原因,内容脚本停留在“runtime.sendMessage”函数上。我使用了Edge 40.15063 Edge控制台显示: “API调用:'runtime.sendMessage'” “脚本块(9)(214,17)。” manifest.json: { "manifest_version": 2, "name": "injecter", "version": "0.1.5
{
"manifest_version": 2,
"name": "injecter",
"version": "0.1.5.9",
"author": "kovler",
"description": "check the page url and then inject a code",
"icons": {
"48": "icons/icon32.png",
"96": "icons/icon96.png"
},
"applications": {
"gecko": {
"id": "test@test.com",
"strict_min_version": "45.0"
}
},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["edge.js", "content.js"]
}],
"background": {
"scripts": ["edge.js", "constants.js", "promises.js", "main.js"],
"persistent": true
},
"permissions": [
"http://*/",
"https://*/",
"storage",
"webNavigation",
"tabs",
"activeTab",
"cookies",
"webRequest",
"webRequestBlocking"
],
"-ms-preload": {
"backgroundScript": "backgroundScriptsAPIBridge.js",
"contentScript": "contentScriptsAPIBridge.js"
}
}
edge.js:
if (typeof chrome == "undefined" || typeof chrome.runtime == "undefined")
chrome = browser;
content.js:
(function(){
function injectLocalScript (content, node) {
var th = document.getElementsByTagName(node)[0];
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.innerHTML = content;
th.appendChild(s);
}
function getAnswer(theMessageEvent) {
if (theMessageEvent) {
if (theMessageEvent.name === "Inject") {
injectLocalScript(theMessageEvent.codeLine, 'body');
console.log("injected");
}
}
}
chrome.runtime.sendMessage({ name: "injectionCompleted" }, getAnswer );
}());
您使用什么版本的Edge?检查后台和内容页中的控制台,它们不会共享错误。手动background.html方法可能也值得尝试-不确定Edge处理持久bg脚本的效果如何。Edge版本为Edge 40.15063。
chrome
已映射到浏览器中的-ms preload
脚本中,您无需再次执行此操作。