javascriptreactjsnext.jsiframeembed

How to silence console.log from third party iframe


Currently, I'm developing a web app using NEXT.js. The deal is that I'm working with a third party iframe which is displaying lots (hundreds) of console.logs. I just want to “mute” the outputs for the iframe.

My code is just and <iframe> with the embed link.

I'm aware there a some similar questions, but none of them are related to third party iframes.

Hope anyone can help a bit here!


Solution

  • It's hard to prove a negative, but if it's a cross-origin frame, I don't think you can do anything about it without proxying the content through your own server1 (thus making it no longer cross-origin).

    You can't access the JavaScript environment of a cross-origin frame, so you can't (for instance) replace console.log with a do-nothing stub.

    If you proxied the frame through your own server1 so it wasn't cross-origin, there are several things you could do, such as injecting code as you passed it through that puts in that do-nothing stub, or doing that client-side. But if you keep it as a cross-origin frame, I think you're stuck with the logs.


    1 loading it from your server, and having your server request the content from the origin server then pass that content back to your page