From 4636ad2960981e23a5220cb675034b5b3fe0c644 Mon Sep 17 00:00:00 2001 From: Archan Datta Date: Wed, 25 Feb 2026 11:43:32 -0400 Subject: [PATCH 1/3] feat: update neko client to have optional debugging --- images/chromium-headful/client/src/plugins/neko.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/images/chromium-headful/client/src/plugins/neko.ts b/images/chromium-headful/client/src/plugins/neko.ts index 90f294ee..2a80945b 100644 --- a/images/chromium-headful/client/src/plugins/neko.ts +++ b/images/chromium-headful/client/src/plugins/neko.ts @@ -15,13 +15,22 @@ declare module 'vue/types/vue' { } } +function isDebugEnabled(): boolean { + const params = new URLSearchParams(location.search) + const debug = params.get('debug') + return debug === '1' || debug === 'true' +} + const plugin: PluginObject = { install(Vue) { - window.$client = new NekoClient() + const client = new NekoClient() .on('error', window.$log.error) .on('warn', window.$log.warn) .on('info', window.$log.info) - .on('debug', window.$log.debug) + if (isDebugEnabled()) { + client.on('debug', window.$log.debug) + } + window.$client = client Vue.prototype.$client = window.$client }, From ce075ff67432142d8f48b5594381005b629d8287 Mon Sep 17 00:00:00 2001 From: Archan Datta Date: Wed, 25 Feb 2026 14:08:50 -0400 Subject: [PATCH 2/3] feat: update logging to be more generic --- .../client/src/plugins/log.ts | 47 ++++++++++++++++--- .../client/src/plugins/neko.ts | 13 +---- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/images/chromium-headful/client/src/plugins/log.ts b/images/chromium-headful/client/src/plugins/log.ts index 09c26d4e..08cffa4a 100644 --- a/images/chromium-headful/client/src/plugins/log.ts +++ b/images/chromium-headful/client/src/plugins/log.ts @@ -21,15 +21,48 @@ declare module 'vue/types/vue' { } } +const noop = () => {} +const noopError = (_: Error) => {} + +const realLoggers: Logger = { + error: (error: Error) => console.error('[%cNEKO%c] %cERR', 'color: #498ad8;', '', 'color: #d84949;', error), + warn: (...log: any[]) => console.warn('[%cNEKO%c] %cWRN', 'color: #498ad8;', '', 'color: #eae364;', ...log), + info: (...log: any[]) => console.info('[%cNEKO%c] %cINF', 'color: #498ad8;', '', 'color: #4ac94c;', ...log), + debug: (...log: any[]) => console.log('[%cNEKO%c] %cDBG', 'color: #498ad8;', '', 'color: #eae364;', ...log), +} + +const offLoggers: Logger = { + error: noopError, + warn: noop, + info: noop, + debug: noop, +} + +const LOG_METHODS: (keyof Logger)[] = ['error', 'warn', 'info', 'debug'] +const DISABLED_LEVELS = ['off', 'none', ''] + +function createLoggerForLevel(level: string): Logger { + const normalized = level.toLowerCase() + if (DISABLED_LEVELS.includes(normalized)) return offLoggers + + const enabledIndex = LOG_METHODS.indexOf(normalized as keyof Logger) + if (enabledIndex === -1 || enabledIndex === LOG_METHODS.length - 1) return realLoggers + + const logger = { ...offLoggers } + for (let i = 0; i <= enabledIndex; i++) { + logger[LOG_METHODS[i]] = realLoggers[LOG_METHODS[i]] + } + return logger +} + +function getLogLevel(): string { + const params = new URL(location.href).searchParams + return params.get('log_level') ?? params.get('logLevel') ?? 'off' +} + const plugin: PluginObject = { install(Vue) { - window.$log = { - error: (error: Error) => console.error('[%cNEKO%c] %cERR', 'color: #498ad8;', '', 'color: #d84949;', error), - warn: (...log: any[]) => console.warn('[%cNEKO%c] %cWRN', 'color: #498ad8;', '', 'color: #eae364;', ...log), - info: (...log: any[]) => console.info('[%cNEKO%c] %cINF', 'color: #498ad8;', '', 'color: #4ac94c;', ...log), - debug: (...log: any[]) => console.log('[%cNEKO%c] %cDBG', 'color: #498ad8;', '', 'color: #eae364;', ...log), - } - + window.$log = createLoggerForLevel(getLogLevel()) Vue.prototype.$log = window.$log }, } diff --git a/images/chromium-headful/client/src/plugins/neko.ts b/images/chromium-headful/client/src/plugins/neko.ts index 2a80945b..90f294ee 100644 --- a/images/chromium-headful/client/src/plugins/neko.ts +++ b/images/chromium-headful/client/src/plugins/neko.ts @@ -15,22 +15,13 @@ declare module 'vue/types/vue' { } } -function isDebugEnabled(): boolean { - const params = new URLSearchParams(location.search) - const debug = params.get('debug') - return debug === '1' || debug === 'true' -} - const plugin: PluginObject = { install(Vue) { - const client = new NekoClient() + window.$client = new NekoClient() .on('error', window.$log.error) .on('warn', window.$log.warn) .on('info', window.$log.info) - if (isDebugEnabled()) { - client.on('debug', window.$log.debug) - } - window.$client = client + .on('debug', window.$log.debug) Vue.prototype.$client = window.$client }, From 6c22f62ec2ab665f04fb8a3c22888da2519d14ad Mon Sep 17 00:00:00 2001 From: Archan Datta Date: Wed, 25 Feb 2026 14:12:37 -0400 Subject: [PATCH 3/3] review: log.ts --- images/chromium-headful/client/src/plugins/log.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/images/chromium-headful/client/src/plugins/log.ts b/images/chromium-headful/client/src/plugins/log.ts index 08cffa4a..7d780e50 100644 --- a/images/chromium-headful/client/src/plugins/log.ts +++ b/images/chromium-headful/client/src/plugins/log.ts @@ -8,8 +8,6 @@ interface Logger { } declare global { - const $log: Logger - interface Window { $log: Logger } @@ -46,11 +44,12 @@ function createLoggerForLevel(level: string): Logger { if (DISABLED_LEVELS.includes(normalized)) return offLoggers const enabledIndex = LOG_METHODS.indexOf(normalized as keyof Logger) - if (enabledIndex === -1 || enabledIndex === LOG_METHODS.length - 1) return realLoggers + if (enabledIndex === -1) return offLoggers - const logger = { ...offLoggers } + const logger: Logger = { ...offLoggers } for (let i = 0; i <= enabledIndex; i++) { - logger[LOG_METHODS[i]] = realLoggers[LOG_METHODS[i]] + const method = LOG_METHODS[i] + ;(logger as any)[method] = realLoggers[method] } return logger }