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/page"
"github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp" "github.com/chromedp/chromedp"
"github.com/chromedp/chromedp/kb"
"github.com/priyanshujain/sanderling/internal/driver" "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)) 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{ var keyMap = map[string]string{
"back": "\b", "enter": kb.Enter,
"home": "\x00", "tab": kb.Tab,
"enter": "\r", "escape": kb.Escape,
"tab": "\t", "up": kb.ArrowUp,
"up": "\x26", "down": kb.ArrowDown,
"down": "\x28", "left": kb.ArrowLeft,
"left": "\x25", "right": kb.ArrowRight,
"right": "\x27",
} }
func (d *Driver) Hierarchy(_ context.Context) (string, error) { func (d *Driver) Hierarchy(_ context.Context) (string, error) {