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.
This commit is contained in:
pj committed 2026-05-03 10:55:42 +07:00
1 parent 1f525b6cdd
commit 65adfb9b2e
1 file changed
+11 -8
+11 -8
View File
@@ -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) {