admin管理员组文章数量:1334659
I'm building a Chrome extension. I need to intercept requests to a specific endpoint to get the response body and use the response in the extension (all ok, no malicious software)
To do that I overwrite window.fetch
function with code:
const originalFetch = window.fetch;
window.fetch = async function (...args) {
const response = await originalFetch(...args);
const request = args[0];
const url = request instanceof Request ? request.url : request instanceof URL ? request.href : request;
if (url.includes('api/search')) {
const data = await response.clone().json();
if (data.myInfo) {
window.dispatchEvent(
new CustomEvent('OnMyInfoLoaded', {
detail: {
myInfo: data.myInfo,
},
}),
);
}
}
return response;
};
This script is injected in manifest:
{
"matches": [
"/*/*"
],
"js": [
"dist/injectCustomFetch.bundle.js"
],
"run_at": "document_start"
}
In 99% cases requests to search
works and I get the data, but sometimes I get 403 forbidden
from server. The server uses cloudflare so I assume cloudflare somehow detects that fetch
is patched? I can't access server logs/cloudflare logs as I'm not the owner of the server
This error is hard to catch too as most of the time it works fine, with occasional 403 and I don't see any pattern
本文标签: javascriptCan Cloudflare detect that i read response body twiceStack Overflow
版权声明:本文标题:javascript - Can Cloudflare detect that i read response body twice? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742375775a2463132.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论