fix: ChatGPT fetch interception failure + bump to 2.0.6

ChatGPT (and potentially other AI services) calls fetch() with a
Request object as the first argument: fetch(new Request(url, opts))
instead of fetch(url, opts). The interceptor only handled the second
form, so ChatGPT's conversation requests passed through unmodified.

Fixed by handling both fetch signatures:
- fetch(url, options) — existing path
- fetch(Request) — new: extracts URL, method, headers, reads body
  via request.text() for JSON/text content types

Also handles non-string body types:
- Blob → text via blob.text()
- ArrayBuffer → text via TextDecoder
- URLSearchParams → string via toString()

These cover the various ways modern frameworks call fetch().

https://claude.ai/code/session_01SWSwDfMVij53bCTNSCLMwn
This commit is contained in:
Claude
2026-03-27 04:07:11 +00:00
parent 8cff1ae382
commit 02c635c4d7
5 changed files with 52 additions and 6 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Silent Send",
"version": "2.0.5",
"version": "2.0.6",
"description": "Intercepts personal info and substitutes it with user-defined replacements before sending to AI services.",
"browser_specific_settings": {
"gecko": {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Silent Send",
"version": "2.0.5",
"version": "2.0.6",
"description": "Intercepts personal info and substitutes it with user-defined replacements before sending to AI services.",
"permissions": [
"storage",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "silent-send",
"version": "2.0.5",
"version": "2.0.6",
"private": true,
"license": "BSL-1.1",
"description": "Browser extension that substitutes personal data before sending to AI services",
+48 -2
View File
@@ -908,14 +908,60 @@
return SKIP_URL_PATTERNS.some(p => p.test(url));
}
window.fetch = async function (url, options) {
window.fetch = async function (input, init) {
if (!settings.enabled || !hasSubstitutions()) {
return originalFetch.call(this, url, options);
return originalFetch.call(this, input, init);
}
// Handle both fetch(url, options) and fetch(Request) signatures
let url, options;
if (input instanceof Request) {
url = input.url;
// Clone the Request so we can read/modify the body
options = {
method: input.method,
headers: input.headers,
body: null, // will read below
mode: input.mode,
credentials: input.credentials,
cache: input.cache,
redirect: input.redirect,
referrer: input.referrer,
signal: input.signal,
};
// Read the body from the Request object
try {
const ct = input.headers.get('content-type') || '';
if (ct.includes('json') || ct.includes('text')) {
options.body = await input.text();
} else {
// Non-text body — pass through unmodified
return originalFetch.call(this, input, init);
}
} catch {
return originalFetch.call(this, input, init);
}
} else {
url = input;
options = init ? { ...init } : {};
}
const urlStr = typeof url === 'string' ? url : url?.url || '';
const method = (options?.method || 'GET').toUpperCase();
// Convert non-string bodies to string where possible
if (options.body && typeof options.body !== 'string' && !(options.body instanceof FormData)) {
try {
if (options.body instanceof Blob) {
options.body = await options.body.text();
} else if (options.body instanceof ArrayBuffer || ArrayBuffer.isView(options.body)) {
options.body = new TextDecoder().decode(options.body);
} else if (options.body instanceof URLSearchParams) {
options.body = options.body.toString();
}
} catch { /* leave as-is */ }
}
// Only intercept POST/PUT/PATCH with a body
if (
(method === 'POST' || method === 'PUT' || method === 'PATCH') &&
+1 -1
View File
@@ -591,7 +591,7 @@
</section>
<footer>
<p>Silent Send v2.0.5</p>
<p>Silent Send v2.0.6</p>
</footer>
</div>