Add grok.com; fix fetch hook on React/Next.js sites (Reddit, Grok, etc.)
Two fixes: 1. grok.com missing from manifest Grok moved from grok.x.ai to grok.com. The extension wasn't activating on grok.com at all (no content script injected). Added to host_permissions and content_scripts in both manifests. 2. Fetch hook bypassed on React/Next.js sites content.js was injected async (after awaiting the document-scanner), so by the time it replaced window.fetch, React/Next.js had already stored a reference to the original. All fetch calls from framework code bypassed the hook entirely. Fix: load early-hook.js as a "world": "MAIN" content script at document_start. This runs synchronously before any page JavaScript, captures the real fetch in window.__ssOriginalFetch, and replaces window.fetch with a lightweight wrapper. When content.js eventually loads, it sets window.__ssInterceptFetch (the real substitution logic) and window.__ssReady = true, activating the wrapper. React's stored fetch reference now routes through the interceptor. Falls back to direct window.fetch replacement if early-hook.js somehow didn't run (e.g. older browser without world: MAIN support). https://claude.ai/code/session_01CwcZK8nqL8pyBH9AxDs9qo
This commit is contained in:
+14
-2
@@ -789,7 +789,9 @@
|
||||
// Fetch Interception — scans ALL POST requests with a body.
|
||||
// Service-agnostic: doesn't depend on URL patterns.
|
||||
// ============================================================
|
||||
const originalFetch = window.fetch;
|
||||
// Use the real fetch captured by early-hook.js (before React stored its reference),
|
||||
// or fall back to whatever window.fetch is now if early-hook.js didn't run.
|
||||
const originalFetch = window.__ssOriginalFetch || window.fetch;
|
||||
|
||||
// URLs to never touch (static assets, analytics, etc.)
|
||||
const SKIP_URL_PATTERNS = [
|
||||
@@ -805,7 +807,7 @@
|
||||
return SKIP_URL_PATTERNS.some(p => p.test(url));
|
||||
}
|
||||
|
||||
window.fetch = async function (url, options) {
|
||||
window.__ssInterceptFetch = async function (url, options) {
|
||||
if (!settings.enabled || !hasSubstitutions()) {
|
||||
return originalFetch.call(this, url, options);
|
||||
}
|
||||
@@ -869,6 +871,16 @@
|
||||
return originalFetch.call(this, url, options);
|
||||
};
|
||||
|
||||
// Activate the fetch hook. If early-hook.js ran first (world: MAIN, document_start),
|
||||
// it already replaced window.fetch with a wrapper that forwards to __ssInterceptFetch
|
||||
// once __ssReady is true — this catches React/Next.js fetch references stored before
|
||||
// content.js loaded. Otherwise fall back to replacing window.fetch directly.
|
||||
if (window.__ssOriginalFetch) {
|
||||
window.__ssReady = true;
|
||||
} else {
|
||||
window.fetch = window.__ssInterceptFetch;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// XMLHttpRequest Interception — same aggressive approach
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user