javascript - 使用 chrome 扩展的重定向循环问题
问题描述
我已经构建了一个 chrome 扩展,它将某些链接转换为附属链接,然后重定向到该附属链接。
更好理解的步骤:
1. 有人访问www.amazon.in,扩展程序通过chrome.webRequest.onBeforeRequest.addListener
2. 转换为另一个 url,如www.linkly.com?q1=param&q2=param。
3. 该链接再次将请求发送回原始 url,即www.amazon.in
在这里,它一次又一次地进行重定向循环。我试过使用types: ['main_frame']
但没有得到解决方案。
清单.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"]
}
背景.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"]
);
}
请帮我解决这个问题。我提前感谢您的时间和支持。
解决方案
推荐阅读
- node.js - 将 YouTube 共享链接转换为在我的项目中嵌入链接
- c - 为什么 cmov 总是返回 t_val?
- php - 将新列添加到 WooCommerce 管理产品列表,其中包含销售产品的折扣百分比
- xml - 解析 XSD 以获取节点列表
- c# - 创建线程会增加功耗和 CPU 消耗
- spring - 关于春季休息日期
- javascript - Nodejs - 使用 docker rest api 的调用
- c++ - C ++如何阻止随机引擎产生负数?
- laravel - 如何将在第一个文本框中键入的文本显示为第二个文本框中的 slug?
- flutter - Flutter Firestore 和 androidx 兼容性问题