stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.85k stars 152 forks source link

Hijack iframe console log #1321

Open cryingpotat0 opened 8 months ago

cryingpotat0 commented 8 months ago

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!

SamVerschueren commented 8 months ago

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.

cryingpotat0 commented 8 months ago

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!