diff --git a/browser_patches/firefox/juggler/TargetRegistry.js b/browser_patches/firefox/juggler/TargetRegistry.js index c1c0f50280c56..afc5166199904 100644 --- a/browser_patches/firefox/juggler/TargetRegistry.js +++ b/browser_patches/firefox/juggler/TargetRegistry.js @@ -286,7 +286,7 @@ const FILE_PICKER_CONTRACT_ID = '@mozilla.org/filepicker;1'; // WebDriver's FilePickerHandler and MockFilePicker do. Content processes always use // nsFilePickerProxy, which asks the parent (FilePickerParent) to create the real picker, // so a parent-side override covers all pages. Pages that intercept file choosers get a -// picker that cancels immediately; everything else is forwarded to the original picker. +// picker that completes with no files; everything else is forwarded to the original picker. class FilePickerOverride { constructor(registry) { this._registry = registry; @@ -327,7 +327,9 @@ class FilePickerOverride { if (original) original.open(callback); else - callback.done(Ci.nsIFilePicker.returnCancel); + // Close the picker without dispatching cancel or changing the input's files. + // Playwright assigns the files separately after the filechooser event. + callback.done(Ci.nsIFilePicker.returnOK); }, isModeSupported: mode => original ? original.isModeSupported(mode) : Promise.resolve(true), appendFilters: filterMask => original?.appendFilters(filterMask), @@ -354,7 +356,7 @@ class FilePickerOverride { get mode() { return original ? original.mode : state.mode; }, get file() { return original ? original.file : null; }, get fileURL() { return original ? original.fileURL : null; }, - get files() { return original ? original.files : null; }, + get files() { return original ? original.files : [][Symbol.iterator](); }, get domFileOrDirectory() { return original ? original.domFileOrDirectory : null; }, get domFileOrDirectoryEnumerator() { return original ? original.domFileOrDirectoryEnumerator : null; }, get domFilesInWebKitDirectory() { return original ? original.domFilesInWebKitDirectory : null; }, diff --git a/browser_patches/firefox/juggler/content/PageAgent.js b/browser_patches/firefox/juggler/content/PageAgent.js index 5397832284018..cd92e82e9c7c1 100644 --- a/browser_patches/firefox/juggler/content/PageAgent.js +++ b/browser_patches/firefox/juggler/content/PageAgent.js @@ -258,7 +258,7 @@ export class PageAgent { _filePickerShown(inputElement) { // Fired by HTMLInputElement::InitFilePicker right before the native picker is opened. // When intercepting, the parent process replaces the native picker with one that - // cancels immediately (see FilePickerOverride in TargetRegistry.js). + // completes with no files (see FilePickerOverride in TargetRegistry.js). if (!this._interceptFileChooserDialog) return; const frame = this._findFrameForNode(inputElement); diff --git a/browser_patches/firefox/patches/bootstrap.diff b/browser_patches/firefox/patches/bootstrap.diff index ca255a8b8b32d..cc015f7c222c6 100644 --- a/browser_patches/firefox/patches/bootstrap.diff +++ b/browser_patches/firefox/patches/bootstrap.diff @@ -481,10 +481,47 @@ index 7929fcdeb59c47dbd2bee9e8d8bfd7ef2e8db87b..0c4c0bc14f8c42276833607daae5f70d mouseOrPointerEvent.pointerId = aMouseEventData.mIdentifier; mouseOrPointerEvent.mModifiers = diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp -index bb523c271733fb3b5be45c990cea9cf4378fae8b..cab093cb55891c0c683c310b42e8601cab5648ad 100644 +index bb523c271733fb3b5be45c990cea9cf4378fae8b..9c2687c13ec7a25b5ce6049715a7fa93a158f87d 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp -@@ -1892,6 +1892,10 @@ Maybe nsFocusManager::SetFocusInner(Element* aNewContent, +@@ -837,17 +837,25 @@ void nsFocusManager::WindowLowered(mozIDOMWindowProxy* aWindow, + } + } + +- // clear the mouse capture as the active window has changed +- PresShell::ReleaseCapturingContent(); +- +- // In addition, reset the drag state to ensure that we are no longer in +- // drag-select mode. +- if (mFocusedWindow) { +- nsCOMPtr docShell = mFocusedWindow->GetDocShell(); +- if (docShell) { +- if (PresShell* presShell = docShell->GetPresShell()) { +- RefPtr frameSelection = presShell->FrameSelection(); +- frameSelection->SetDragState(false); ++ nsCOMPtr loweredDocShell = window->GetDocShell(); ++ // An automated page remains focused when another page's window is activated. ++ // Preserve its native capture and selection drag just as we preserve focus. ++ bool preserveInputState = ++ XRE_IsContentProcess() && loweredDocShell && ++ nsDocShell::Cast(loweredDocShell)->ShouldOverrideHasFocus(); ++ if (!preserveInputState) { ++ // clear the mouse capture as the active window has changed ++ PresShell::ReleaseCapturingContent(); ++ ++ // In addition, reset the drag state to ensure that we are no longer in ++ // drag-select mode. ++ if (mFocusedWindow) { ++ nsCOMPtr docShell = mFocusedWindow->GetDocShell(); ++ if (docShell) { ++ if (PresShell* presShell = docShell->GetPresShell()) { ++ RefPtr frameSelection = presShell->FrameSelection(); ++ frameSelection->SetDragState(false); ++ } + } + } + } +@@ -1892,6 +1900,10 @@ Maybe nsFocusManager::SetFocusInner(Element* aNewContent, (GetActiveBrowsingContext() == newRootBrowsingContext); } @@ -495,7 +532,7 @@ index bb523c271733fb3b5be45c990cea9cf4378fae8b..cab093cb55891c0c683c310b42e8601c // Exit fullscreen if a website focuses another window if (StaticPrefs::full_screen_api_exit_on_windowRaise() && !isElementInActiveWindow && (aFlags & FLAG_RAISE)) { -@@ -2453,6 +2457,7 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear, +@@ -2453,6 +2465,7 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear, bool aIsLeavingDocument, bool aAdjustWidget, bool aRemainActive, Element* aElementToFocus, uint64_t aActionId) { @@ -503,7 +540,7 @@ index bb523c271733fb3b5be45c990cea9cf4378fae8b..cab093cb55891c0c683c310b42e8601c LOGFOCUS(("<>", aActionId)); // hold a reference to the focused content, which may be null -@@ -2496,6 +2501,13 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear, +@@ -2496,6 +2509,13 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear, return true; } @@ -517,7 +554,7 @@ index bb523c271733fb3b5be45c990cea9cf4378fae8b..cab093cb55891c0c683c310b42e8601c // Keep a ref to presShell since dispatching the DOM event may cause // the document to be destroyed. RefPtr presShell = docShell->GetPresShell(); -@@ -2677,7 +2689,11 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear, +@@ -2677,7 +2697,11 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear, } // check if a different window was focused @@ -530,7 +567,7 @@ index bb523c271733fb3b5be45c990cea9cf4378fae8b..cab093cb55891c0c683c310b42e8601c } else if (GetActiveBrowsingContext()) { // Otherwise, the blur of the element without blurring the document // occurred normally. Call UpdateCaret to redisplay the caret at the right -@@ -3266,7 +3282,9 @@ void nsFocusManager::RaiseWindow(nsPIDOMWindowOuter* aWindow, +@@ -3266,7 +3290,9 @@ void nsFocusManager::RaiseWindow(nsPIDOMWindowOuter* aWindow, } } diff --git a/packages/playwright-core/browsers.json b/packages/playwright-core/browsers.json index 66309c26af707..80f2b971edac6 100644 --- a/packages/playwright-core/browsers.json +++ b/packages/playwright-core/browsers.json @@ -17,7 +17,7 @@ }, { "name": "firefox", - "revision": "1575", + "revision": "1577", "installByDefault": true, "browserVersion": "159.0", "title": "Firefox"