I want to embed a cross-origin iframe (for example: a Google page) in my HTML and intercept or mock some of its network requests. It would be without using browser extensions, proxies, or external tools. It needs to work out of the box when a user visits the page.
<iframe src="https://www.google.com" description="My embedded browser"></iframe>
Is there any way to intercept or stub requests from this iframe using only vanilla JavaScript and HTML? Or is this blocked by browser security policies?
My goal here is mostly to learn. I’m experimenting with how HTTP, certificates, and HTML interact, and I was curious if I could reuse a frontend with a custom backend.
const origFetch = window.fetch; window.fetch = mockFetch. 2. If you do NOT own the page, you can consider to Your browser will request data from an IP address. If you modify your host file127.0.0.1 api.example.com, you can mock it all you want. You likely have to issue a certificate so localhost runs https