fix: call focus() twice to workaround firefox not focusing element (#23535)

When focus is moved from one tab to another, it might require calling
`focus()` twice to actually focus an element in Firefox.

Fixes https://github.com/microsoft/playwright/issues/23117
This commit is contained in:
Andrey Lushnikov 2023-06-05 16:46:52 -07:00 committed by GitHub
parent eacfff8127
commit 3a00fc4edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -793,6 +793,9 @@ export class InjectedScript {
// contenteditable to the new element. However, blurring the previous one helps.
(activeElement as HTMLElement | SVGElement).blur();
}
// On firefox, we have to call focus() twice to actually focus an element in certain
// scenarios.
(node as HTMLElement | SVGElement).focus();
(node as HTMLElement | SVGElement).focus();
if (resetSelectionIfNotFocused && !wasFocused && node.nodeName.toLowerCase() === 'input') {