Forward webview console log messages to browser console #13084
Merged
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.
What it does
This ensures that webview console logs are correctly propagated to the backend logger.
Webview are rendered inside of an IFrame this means console logs are isolated and are not forwarded to the backend logger
(in contrast to console logs of the main frontend process).
This change extends the default script injected into webviews to override the global console and send a log message via the
postMessage
API instead. This event is than handled by the `Webview´ base class and forwarded to the browser console.In addition to forwarding to the backend logger this also makes it easier to identify log messages that are coming from webviews as they are now prefixed with [webview: ]
Contributed on behalf of STMicroelectronics
How to test
This can be tested with any vsocde-extension that provides a webview with console logs.
I used the CatCoding webview sample and added the following console logs to the webview main script:
The
vsix
for this customized cat coder can be found here:cat-coding-0.0.1.zip
To test, add it to the plugin folder,
open the Theia application and then use the
Cat Coding: Start coding session
command to open the webview.Expected result: The console logs mentioned above should show up in the browser console and the backend console.
Follow-ups
Review checklist
Reminder for reviewers