Skip to content

Commit

Permalink
fix(src/preview.js): hijack console before importing modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Mar 13, 2024
1 parent 138dcbc commit 34d07be
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/preview.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import application from 'socket:application'
import { inspect } from 'socket:util'

globalThis.RUNTIME_APPLICATION_ALLOW_MULTI_WINDOWS = true

const currentWindow = await application.getCurrentWindow()
setTimeout(() => {
const consoleMethods = ['log', 'error', 'info', 'warn', 'debug']
for (const method of consoleMethods) {
const original = console[method]
globalThis.console[method] = (...args) => {
original.call(console, ...args)
let currentWindow = null
const consoleMethods = ['log', 'error', 'info', 'warn', 'debug']
for (const method of consoleMethods) {
const original = console[method]
globalThis.console[method] = async (...args) => {
if (!currentWindow) {
currentWindow = await application.getCurrentWindow()
}
original.call(console, ...args)
if (currentWindow) {
// @ts-ignore
currentWindow.channel.postMessage({
[method]: [inspect(...args)]
})
}
}
}, 2048)
}

import application from 'socket:application'
import { inspect } from 'socket:util'

const previewWindowTitleBar = 38
const previewWindowMargin = 12
Expand Down

0 comments on commit 34d07be

Please sign in to comment.