feat: Add integrated console and error reporting to CodeEmbed #1135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an integrated Console Panel to the interactive CodeEmbed component. It allows users to see
console.logoutputs, warnings, and runtime errors (such as syntax errors or missing arguments) directly within the website's interface, without needing to open the browser's developer tools.Motivation
Currently, if a user—especially a beginner learning p5.js—makes a mistake in an interactive sketch (e.g., calling rect() without arguments), the sketch fails silently. This lack of feedback creates a significant barrier to learning. This feature closes the feedback loop by surfacing errors and logs immediately, making the documentation more interactive and helpful.
Implementation Details
log,info,warn, anderrorlevels with distinct visual styling (e.g., red background for errors).console.*methods and globalwindow.onerror/onunhandledrejectionevents inside the sandbox and forwards them to the parent window viapostMessage.Test Plan
I have verified the changes manually with the following scenarios:
console.log("hello p5")in an editor -> confirmed the message appears in the panel.Checklist