How to silence console output on an iframe

a working fiddle here

var iframe = document.createElement('iframe');
iframe.setAttribute("src", "yourIframeURL");
document.body.appendChild(iframe);
iframeWindow = iframe.contentWindow;
iframeWindow.console.log = function() { /* nop */ };

This works on Mozilla,Chrome ,Safari


I have come accross a use case, where the iframes were created by a 3rd party library, so I had to get them from document instead of creating them:

const iframes = Array.from(document.getElementsByTagName('iframe'));
for (const item of iframes) {
  item.contentWindow.console.log = () => { /* nop */ };
}