我正在开发Chrome扩展程序,将javascript,css文件重定向到其他主机。但它不适用于https和xhr请求。 如果details.type不是xmlhttprequest,它可以工作; 我试图在onHeadersReceived上添加我的监听器。但是发生了同样的错误。
错误:
t=1824814 [st=0] +REQUEST_ALIVE [dt=5]
t=1824814 [st=0] +URL_REQUEST_DELEGATE [dt=5]
t=1824814 [st=0] DELEGATE_INFO [dt=5]
--> delegate_info = "extension Redirect"
t=1824819 [st=5] CHROME_EXTENSION_REDIRECTED_REQUEST
--> extension_id = "kgggbgffjdlccdflannojbfnabeecefm"
t=1824819 [st=5] -URL_REQUEST_DELEGATE
t=1824819 [st=5] +URL_REQUEST_START_JOB [dt=0]
--> load_flags = 737536 (BYPASS_DATA_REDUCTION_PROXY | IGNORE_LIMITS | MAYBE_USER_GESTURE | REPORT_RAW_HEADERS | VERIFY_EV_CERT)
--> method = "GET"
--> priority = "HIGHEST"
--> url = "https://www.example.com/dojo/nls/dojo_mn-mn.js"
t=1824819 [st=5] URL_REQUEST_REDIRECT_JOB
--> reason = "Delegate"
t=1824819 [st=5] URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED
--> HTTP/1.1 307 Internal Redirect
Location: https://anotherexample.com/dojo/nls/dojo_mn-mn.js
Non-Authoritative-Reason: Delegate
t=1824819 [st=5] URL_REQUEST_DELEGATE [dt=0]
t=1824819 [st=5] CANCELLED
t=1824819 [st=5] -URL_REQUEST_START_JOB
--> net_error = -3 (ERR_ABORTED)
t=1824819 [st=5] URL_REQUEST_DELEGATE [dt=0]
t=1824819 [st=5] -REQUEST_ALIVE
我的代码是:
chrome.webRequest.onBeforeRequest.addListener(
function(details){
var path=getLocation(details.url).pathname;
if(!path.endsWith(".css")||path.endsWith(".js"))){
return {cancel:false};
}
return {
redirect:"https://anotherexample.com"+path
};
},{urls: ["https://www.example.com/*"]},["blocking"]
);