我正在更新重定向某些请求的Chrome扩展程序。它在Chrome(Windows)上运行良好,但在Chrome(Mac)上运行不佳。
这是清单:
"permissions": [
"webRequest",
"webRequestBlocking",
"*://*.facebook.com/*",
"*://*.messenger.com/*",
"storage",
],
这是背景:
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (flags.isUserInvisible) {
var newurl = details.url;
if (newurl.indexOf('hijacked') >= 0) return;
var regex = /(&state=\D*)/;
newurl = newurl.replace(regex,"");
var regex = /(&idle=\d*)/;
newurl = newurl.replace(regex,"");
return {redirectUrl: newurl+"&state=offline&hijacked=1"};
}
}, { urls: aRedirerect }, ['blocking']);
我基本上从请求中删除了两个字段(状态和空闲)并添加了另一个(状态)。我还添加了一个被劫持的'字段,以避免它一次又一次地重定向。
它工作得很好......在Windows Chrome上!当我在iOS chrome上试用它时,我收到以下错误:
XMLHttpRequest cannot load https://2-edge-chat.facebook.com/pull?channel=p_1000&msgr_region=PRN.
Redirect from 'https://2-edge-chat.facebook.com/pull?channel=p_1000&msgr_region=PRN'
to 'https://2-edge-chat.facebook.com/pull?channel=p_100&msgr_region=PRN&state=offline&hijacked=1'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://www.facebook.com' is therefore not allowed access.
我理解CORS政策是什么阻碍。我不明白这就是为什么它阻止它自己的起源以及为什么它只发生在Mac上。