webcontainer-core icon indicating copy to clipboard operation
webcontainer-core copied to clipboard

Hijack iframe console log

Open cryingpotat0 opened this issue 2 years ago • 2 comments

I'm running a React app in a webcontainer that has some console.log's scattered around. Unfortunately I'm not able to display this output in my app, it just goes into the devtools console of the browser (since its the underlying iframe doing the logging).

Is there a way to intercept these console logs? If not, could the core webcontainer iframe allow for a postMessage to listen to this output? I couldn't find any details about this in the docs or other issues, please let me know if I missed something!

cryingpotat0 avatar Feb 10 '24 14:02 cryingpotat0

Hey @cryingpotat0 👋 ! I assume you are talking about using WebContainer API (https://webcontainers.io/)? Currently we don't have anything setup to intercept console output from the iframe. I'll create an internal ticket. Additional context for the use case is always welcome.

SamVerschueren avatar Feb 15 '24 07:02 SamVerschueren

Yep I am talking about the WebContainer API! I'm building a more powerful alternative to Sandpack called Cannon. I need to be able to intercept console output to actually show any logs the user has! Not having this feature makes WebContainers basically infeasible for in-browser codeblocks since you can't show your console output easily. Please let me know if I'm missing a simple workaround, but I couldn't find any!

cryingpotat0 avatar Feb 16 '24 03:02 cryingpotat0