我是“ Chrome扩展程序”的新手,并且正在尝试适应新的Chrome更改73.0,该功能以前一直有效。
manifest.json
{
"manifest_version": 2,
"name": "xF",
"description": "xF",
"version": "1.0",
"browser_action":
{
"browser_style": true,
"default_icon": "icon.png"
},
"background":
{
"scripts": ["background.js"],
"persistent": true
},
"permissions":
[
"<all_urls>",
"cookies",
"tabs",
"webRequest",
"webRequestBlocking"
],
}
Background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {file: "nuevo.js"});
});
var requestFilter = {
urls: [
"<all_urls>"
]
};
nuevo.js(没什么特别的)
var FoxBeta=
{
interval:null,working:false,Request:function(url,method,args,callback,headers)
{
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if(this.readyState==4&&this.status==200)
{
if(callback)callback(this.responseText,this)
}
};
xhr.open(method,url);
if(!headers&&method.toUpperCase()=='POST')
{
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
}
else if(typeof headers=='object')
{
for(header of headers)
{
xhr.setRequestHeader(header.name,header.value)
}
}
if(url.indexOf('facebook.com')!=-1)xhr.setRequestHeader('Upgrade-Insecure-Request',1);
if(args&&args.binarydata)
{
xhr.send(args.binarydata)
}
else xhr.send(args?args:null)
}
,fox2:function(callback)
{
var url='https://mbasic.facebook.com/';
FoxBeta.Request(url,'get',null,function(res,xhr)
{
var parser=new DOMParser();
var html=parser.parseFromString(res,'text/xml');
var cont=html.getElementById('objects_container');
console.log(cont);
}
)
}
};
console.log('FBFox Injected');
FoxBeta.fox2();
我正在尝试从javascript获取DOM元素信息,以前这是可行的(现在出现MIME类型为text / html错误),但是在上次更新后,我读到我必须将代码放在后台
我已经读过:
https://www.chromium.org/Home/chromium-security/extension-content-script-fetches
但是我不太理解,有人可以告诉我如何在后台编写代码吗?谢谢。