Post

Replies

Boosts

Views

Activity

Reply to How to modify the global window object in Safari Extensions?
I'll set aside if it will be approved for the public but you could use script injection. function injectScript() { const script = document.createElement('script'); script.textContent = ` // Store the original fetch const originalFetch = window.fetch; // Decorate fetch with your custom logic window.fetch = function(...args) { // Your custom logic here console.log('Fetch intercepted:', args[0]); // Example: Add custom headers if (args[1] && args[1].headers) { args[1].headers = { ...args[1].headers, 'X-Custom-Header': 'MyValue' }; } // Call original fetch with modified arguments return originalFetch.apply(this, args); }; `; // Inject script into webpage (document.head || document.documentElement).appendChild(script); // Clean up - remove the script tag after injection script.remove(); } // Execute the injection when content script loads injectScript();
3w