browser_press_key: Enter sends no keypress; punctuation keys (",") get keyCode 0 and an empty code

Aperta
#76 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
devtools, web-dev

Direzione di ricerca

The key handling sits in extension/background.js under case 'press_key', with the VK_CODES map and the one-character text logic next to it. Start by reproducing the repro page from the issue and logging keydown, keypress and keyup. Done means Enter fires keypress 13 and the comma key reports keyCode 188 with code "Comma", while the letter 'a' control keeps working.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: 1.30.3 (extension + server), Windows 11, Chrome 155.

What happens

On a plain <input> with listeners for keydown / keypress / keyup (all events isTrusted: true), measured twice:

Call Events the page receives Real keyboard in Chrome
browser_press_key({key: "Enter"}) keydown 13, keyup 13 - no keypress keydown 13, keypress 13, keyup 13
browser_press_key({key: ","}) keydown keyCode 0, code "", keypress 44, keyup keyCode 0 keydown 188, code "Comma", keypress 44, keyup 188
browser_press_key({key: ",", code: "Comma"}) code "Comma", but keyCode still 0 on keydown/keyup 188
browser_press_key({key: "a"}) (control) keydown 65 KeyA, keypress 97, keyup 65 same - correct

Why it matters

A common tag / chip input pattern commits the typed text on Enter or comma, and many implementations listen on
keypress or check keyCode === 188. With the tool such inputs never turn the text into a tag, and there is no way
around it from the page: synthetic (untrusted) events are ignored by those widgets.

Cause (v1.30.3, extension/background.js, case 'press_key', ~6225-6270)

  • text is only set for one-character keys (etTegn), so Enter is sent with text: '' and Chrome generates no
    keypress. Chrome's own Enter carries text: "\r" (and unmodifiedText: "\r").
  • VK_CODES covers navigation keys, letters and digits only, so punctuation gets no windowsVirtualKeyCode
    (keyCode 0), and code falls back to the key itself (","), which Chrome does not accept as a code.

Suggested fix

  • Enter: send text: "\r", unmodifiedText: "\r" on keyDown (without modifiers).
  • Add the US-layout punctuation to the key map, e.g. , 188 Comma, . 190 Period, - 189 Minus, = 187 Equal,
    ; 186 Semicolon, ' 222 Quote, / 191 Slash, \ 220 Backslash, [ 219 BracketLeft, ] 221 BracketRight,
    ` 192 Backquote - and derive code from it instead of using the character.

Repro

<input id="i"><script>
for (const t of ['keydown','keypress','keyup'])
  i.addEventListener(t, e => console.log(t, e.key, e.code, e.keyCode, e.which));
</script>

Focus the input, then browser_press_key({key:"Enter"}) and browser_press_key({key:","}).

Lingua principale
JavaScript
Stelle
52
Fork
17
Merge medio
4g 2h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Agent360dk/browser-mcp

Tutte le issue di Agent360dk/browser-mcp

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.