@@ -502,36 +502,45 @@ export class PageAgent {
502502 repeat,
503503 keyCode
504504 } ) ;
505- if ( type === 'keydown' ) {
506- if ( text && text !== key ) {
507- tip . commitCompositionWith ( text , keyEvent ) ;
508- } else {
509- const flags = 0 ;
510- // On macOS, Firefox treats Option+<printable key> as text input. Empty text
511- // means no text should be inserted, so we consume keydown after the page
512- // has seen it, which prevents the keypress, same as in Chromium and WebKit.
513- const suppressTextInput = ! text && [ ...key ] . length === 1 && Services . appinfo . OS === 'Darwin' ;
514- if ( ! suppressTextInput ) {
515- tip . keydown ( keyEvent , flags ) ;
505+ const windowUtils = frame . domWindow ( ) . windowUtils ;
506+ const microTaskLevel = windowUtils . microTaskLevel ;
507+ // The actor's WebIDL callback raises the microtask level. Reset it while
508+ // dispatching so checkpoints run between DOM events, as with native input.
509+ windowUtils . microTaskLevel = 0 ;
510+ try {
511+ if ( type === 'keydown' ) {
512+ if ( text && text !== key ) {
513+ tip . commitCompositionWith ( text , keyEvent ) ;
516514 } else {
517- const dispose = helper . addEventListener ( this . _docShell . chromeEventHandler , 'keydown' , event => {
518- if ( event . altKey && ! event . ctrlKey && ! event . metaKey )
519- event . preventDefault ( ) ;
520- } , { capture : true , mozSystemGroup : true } ) ;
521- try {
515+ const flags = 0 ;
516+ // On macOS, Firefox treats Option+<printable key> as text input. Empty text
517+ // means no text should be inserted, so we consume keydown after the page
518+ // has seen it, which prevents the keypress, same as in Chromium and WebKit.
519+ const suppressTextInput = ! text && [ ...key ] . length === 1 && Services . appinfo . OS === 'Darwin' ;
520+ if ( ! suppressTextInput ) {
522521 tip . keydown ( keyEvent , flags ) ;
523- } finally {
524- dispose ( ) ;
522+ } else {
523+ const dispose = helper . addEventListener ( this . _docShell . chromeEventHandler , 'keydown' , event => {
524+ if ( event . altKey && ! event . ctrlKey && ! event . metaKey )
525+ event . preventDefault ( ) ;
526+ } , { capture : true , mozSystemGroup : true } ) ;
527+ try {
528+ tip . keydown ( keyEvent , flags ) ;
529+ } finally {
530+ dispose ( ) ;
531+ }
525532 }
526533 }
534+ } else if ( type === 'keyup' ) {
535+ if ( text )
536+ throw new Error ( `keyup does not support text option` ) ;
537+ const flags = 0 ;
538+ tip . keyup ( keyEvent , flags ) ;
539+ } else {
540+ throw new Error ( `Unknown type ${ type } ` ) ;
527541 }
528- } else if ( type === 'keyup' ) {
529- if ( text )
530- throw new Error ( `keyup does not support text option` ) ;
531- const flags = 0 ;
532- tip . keyup ( keyEvent , flags ) ;
533- } else {
534- throw new Error ( `Unknown type ${ type } ` ) ;
542+ } finally {
543+ windowUtils . microTaskLevel = microTaskLevel ;
535544 }
536545 }
537546
0 commit comments