Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions browser_patches/firefox/juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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; },
Expand Down
2 changes: 1 addition & 1 deletion browser_patches/firefox/juggler/content/PageAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
49 changes: 43 additions & 6 deletions browser_patches/firefox/patches/bootstrap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t> 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<nsIDocShell> docShell = mFocusedWindow->GetDocShell();
- if (docShell) {
- if (PresShell* presShell = docShell->GetPresShell()) {
- RefPtr<nsFrameSelection> frameSelection = presShell->FrameSelection();
- frameSelection->SetDragState(false);
+ nsCOMPtr<nsIDocShell> 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<nsIDocShell> docShell = mFocusedWindow->GetDocShell();
+ if (docShell) {
+ if (PresShell* presShell = docShell->GetPresShell()) {
+ RefPtr<nsFrameSelection> frameSelection = presShell->FrameSelection();
+ frameSelection->SetDragState(false);
+ }
}
}
}
@@ -1892,6 +1900,10 @@ Maybe<uint64_t> nsFocusManager::SetFocusInner(Element* aNewContent,
(GetActiveBrowsingContext() == newRootBrowsingContext);
}

Expand All @@ -495,15 +532,15 @@ 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) {
+
LOGFOCUS(("<<Blur begin actionid: %" PRIu64 ">>", 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;
}

Expand All @@ -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> 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
Expand All @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"name": "firefox",
"revision": "1575",
"revision": "1577",
"installByDefault": true,
"browserVersion": "159.0",
"title": "Firefox"
Expand Down
Loading