all repos — sz-chrome-remote-cdp @ 31afcecdd849529bc5d6ae0719313f0f37e7cebc

pi-browser-harness, patched to drive a Chrome on another host over CDP, with castle_cdp_search web search

feat(util): add pure keycodes and safeJs template helper
amankumarsingh77 amankumarsingh7702@gmal.com
Sat, 02 May 2026 15:36:13 +0530
commit

31afcecdd849529bc5d6ae0719313f0f37e7cebc

parent

64cb4c87978434f478227fa2ea97277ae50269aa

2 files changed, 32 insertions(+), 0 deletions(-)

jump to
A src/util/js-template.ts

@@ -0,0 +1,20 @@

+/** + * Build a JavaScript source string with safely-interpolated values. + * Every interpolated value is JSON.stringify'd, so strings, numbers, + * objects, and special characters all become valid JS literals. + * + * This is the ONLY supported way to build evaluation source in the + * codebase — never use raw template literals for JS that crosses the + * CDP boundary. + */ +export const safeJs = ( + strings: TemplateStringsArray, + ...values: ReadonlyArray<unknown> +): string => { + let out = strings[0] ?? ""; + for (let i = 0; i < values.length; i++) { + out += JSON.stringify(values[i]); + out += strings[i + 1] ?? ""; + } + return out; +};
A src/util/keycodes.ts

@@ -0,0 +1,12 @@

+const VIRTUAL_KEY_CODES: Readonly<Record<string, number>> = { + Enter: 13, Tab: 9, Backspace: 8, Escape: 27, Delete: 46, " ": 32, + ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40, + Home: 36, End: 35, PageUp: 33, PageDown: 34, +}; + +export const SPECIAL_KEYS: ReadonlyArray<string> = Object.keys(VIRTUAL_KEY_CODES); + +export const virtualKeyCode = (key: string): number => + VIRTUAL_KEY_CODES[key] ?? (key.length === 1 ? key.charCodeAt(0) : 0); + +export const keyCode = (key: string): string => key;