From 65adfb9b2e2297139641f73aa1eabab40ff06f07 Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 3 May 2026 10:55:42 +0700 Subject: [PATCH] fix(chrome): correct PressKey mappings to chromedp/kb constants Old keyMap had "home":"\x00" (NUL byte) and arrow keys mapped to random punctuation runes (\x25-\x28 = % & ' () instead of arrow keys. "escape" was missing entirely while the V8 runtime emits it. Drop back/home (no browser navigation semantics) and route the remaining keys through chromedp/kb constants so they actually dispatch as the named keys. --- internal/driver/chrome/driver.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/driver/chrome/driver.go b/internal/driver/chrome/driver.go index a6dc32c..92f6c4a 100644 --- a/internal/driver/chrome/driver.go +++ b/internal/driver/chrome/driver.go @@ -13,6 +13,7 @@ import ( "github.com/chromedp/cdproto/page" "github.com/chromedp/cdproto/runtime" "github.com/chromedp/chromedp" + "github.com/chromedp/chromedp/kb" "github.com/priyanshujain/sanderling/internal/driver" ) @@ -191,15 +192,17 @@ func (d *Driver) PressKey(_ context.Context, key string) error { return chromedp.Run(d.tabCtx, chromedp.KeyEvent(k)) } +// keyMap covers the keys web specs may emit (enter/tab/escape/arrows). +// "back"/"home" are intentionally absent: backspace/NUL have no navigation +// semantics in a browser, and the V8 action mix already excludes them. var keyMap = map[string]string{ - "back": "\b", - "home": "\x00", - "enter": "\r", - "tab": "\t", - "up": "\x26", - "down": "\x28", - "left": "\x25", - "right": "\x27", + "enter": kb.Enter, + "tab": kb.Tab, + "escape": kb.Escape, + "up": kb.ArrowUp, + "down": kb.ArrowDown, + "left": kb.ArrowLeft, + "right": kb.ArrowRight, } func (d *Driver) Hierarchy(_ context.Context) (string, error) {