From 3a00fc4edf1c6f1a7c7bf6cdd203a461c1387ed4 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 5 Jun 2023 16:46:52 -0700 Subject: [PATCH] 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 --- packages/playwright-core/src/server/injected/injectedScript.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 3b2703e51a..99caa7f40d 100644 --- a/packages/playwright-core/src/server/injected/injectedScript.ts +++ b/packages/playwright-core/src/server/injected/injectedScript.ts @@ -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') {