我构建了一个chrome扩展程序,该扩展程序将某些链接转换为会员链接,然后重定向到该会员链接。
更好理解的步骤:
1.有人访问 www.amazon.in ,扩展名通过chrome.webRequest.onBeforeRequest.addListener
获取
2.将该网址转换为另一个网址,例如 www.linkly.com?q1=param&q2=param 。
3.该链接再次将请求发送回原始URL,即 www.amazon.in
在这里,它一次又一次地进行重定向循环。我尝试使用types: ['main_frame']
,但未获得解决方案。
manifest.json:
{
"manifest_version":2,
"name": "ExtName",
"description": "Ext Description",
"version":"1.0",
"browser_action":{
"default_popup":"index.html"
},
"icons": {
"16": "ic_launcher.png",
"48": "ic_launcher.png",
"128": "ic_launcher.png"
},
"background": {
"scripts": ["app/background.js","lib/jquery.min.js"],
"persistent": true
},
"content_scripts":[
{
"matches": ["http://*/*", "https://*/*", "file:///*/*"],
"css":["css/styles.css"],
"js":["lib/jquery.min.js"]
}
],
"web_accessible_resources": ["css/styles.css"],
"permissions": ["tabs","activeTab", "http://*/*", "https://*/*", "file:///*/*", "storage","webRequest","webRequestBlocking"]
}
background.js:
chrome.storage.sync.get(["prefs"],function(data){
var obj=JSON.parse(data.prefs);
uid=obj._userID;
updateLinks(uid);
});
function updateLinks(uid){
var redirUrl;
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if(typeof uid!=="undefined"){
redirUrl = "https://xredir.com/?pub_id=xxxx&subid="+uid+"&source=xxxx&url="+encodeURI(details.url);
}else{
redirUrl = "https://xredir.com/?pub_id=xxxx&source=xxxx&url="+encodeURI(details.url);
}
if(details.type=="main_frame"){
return {redirectUrl: redirUrl};
}
},
{urls: ["*://www.flipkart.com/*", "*://www.amazon.com/*", "*://www.amazon.in/*","*://www.jabong.com/*"],types: ['main_frame']},
["blocking"]
);
}
请帮助我解决这个问题。感谢您的宝贵时间和事先的支持。