Javascript chrome.tabs.executeScript事件don';你不再工作了?
我有下面的代码,直到上周才开始工作,但现在当我再次执行时,它就不起作用了 基于我的测试,使用Javascript chrome.tabs.executeScript事件don';你不再工作了?,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我有下面的代码,直到上周才开始工作,但现在当我再次执行时,它就不起作用了 基于我的测试,使用chrome.tabs.onUpdated.addListener事件可以很好地工作,但是我在msgBox.js文件中有一些字符串,这些字符串会导致编码错误(UTF-8/ANSI),因此需要使用chrome.tabs.executeScript执行msgBox.js文件中的所有脚本 msgBox.js function msg() { alert("hello!"); } msg(); c
chrome.tabs.onUpdated.addListener
事件可以很好地工作,但是我在msgBox.js文件中有一些字符串,这些字符串会导致编码错误(UTF-8/ANSI),因此需要使用chrome.tabs.executeScript
执行msgBox.js文件中的所有脚本
msgBox.js
function msg()
{
alert("hello!");
}
msg();
chrome.webRequest.onCompleted.addListener(
function onWindowLoad() {
chrome.tabs.executeScript(null, {
file: "msgBox.js"
}, function() {
});
}
,
{
urls: ["<all_urls>"],
types: ["main_frame"]
},
["responseHeaders"]
);
event.js
function msg()
{
alert("hello!");
}
msg();
chrome.webRequest.onCompleted.addListener(
function onWindowLoad() {
chrome.tabs.executeScript(null, {
file: "msgBox.js"
}, function() {
});
}
,
{
urls: ["<all_urls>"],
types: ["main_frame"]
},
["responseHeaders"]
);
chrome.webRequest.onCompleted.addListener(
函数onWindowLoad(){
chrome.tabs.executeScript(null{
文件:“msgBox.js”
},函数(){
});
}
,
{
URL:[“”],
类型:[“主框架”]
},
[“负责人”]
);
manifest.json
{
"background": {
// "page": "popup.html"
"scripts": ["event.js"]
},
"description": "Media Player for Flash",
"manifest_version": 2,
"name": "Media Player",
"icons": {
"128" : "picture/flash128.png" ,
"48" : "picture/flash48.png"
},
"web_accessible_resources": [
"event.js"
],
"content_scripts": [
{
"matches": ["<all_urls>", "*://*/*", "http://*/*", "https://*/*"],
"js": ["event.js"],
"run_at": "document_end",
"all_frames": true
}
],
"permissions": [ "tabs", "background", "activeTab", "<all_urls>", "webNavigation", "webRequest", "http://*/*", "https://*/*", "*://*/*" ],
"version": "1.0"
}
{
“背景”:{
//“页面”:“popup.html”
“脚本”:[“event.js”]
},
“说明”:“Flash媒体播放器”,
“清单版本”:2,
“名称”:“媒体播放器”,
“图标”:{
“128”:“picture/flash128.png”,
“48”:“picture/flash48.png”
},
“网络可访问资源”:[
“event.js”
],
“内容脚本”:[
{
“匹配项”:[“”,“*:/*/*/*”,“http://*/*”,“https://*/*”],
“js”:[“event.js”],
“运行时间”:“文件结束时间”,
“所有帧”:正确
}
],
“权限”:[“选项卡”、“背景”、“活动选项卡”、“网页导航”、“网页请求”、“http://*/*”、“https://*/*”、“*://*/*”],
“版本”:“1.0”
}
有什么问题吗
欢迎任何帮助。根据
null不是“executeScript”中对象的有效选项,请尝试在其位置使用“字符串”。至少在试图复制和修复时,它对我起了作用
编辑:虽然这并不能解释为什么它以前工作过,但停止了您使用的是哪个版本的Google Chrome?版本50.0.2661.102(64位)Oops,只是意识到我还没有更新,因为我也不再为自己工作了。道歉。在我更新之前,它不使用“null”,但我一改为“string”就使用了,所以我认为这是itOK,我认为Google Chrome已经阻止了在最新版本的浏览器中使用
Chrome.tabs.executeScript
,就像我已经在想的那样。@Franciscocamilo。这个错误似乎不言自明。只需将文件转换为UTF-8,这应该是固定的。您几乎可以在任何文本编辑器中转换它。例如,在记事本>文件>另存为>编码下拉列表中选择UTF-8。(但我不确定该文件以前是如何使用不正确的编码工作的。)