From 82745ae4d2977580db785d7ff831522d8088cd41 Mon Sep 17 00:00:00 2001 From: Niklas Baumgardner Date: Mon, 27 May 2024 16:38:53 +0000 Subject: [PATCH] Bug 1897371 - Handle selectionchange events in screenshots overlay.r=kcochrane Differential Revision: https://phabricator.services.mozilla.com/D210813 --- browser/actors/ScreenshotsComponentChild.sys.mjs | 7 +++++-- .../tests/browser/browser_text_selectionAPI_test.js | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/browser/actors/ScreenshotsComponentChild.sys.mjs b/browser/actors/ScreenshotsComponentChild.sys.mjs index 5916281cacac..d4bd47a4a865 100644 --- a/browser/actors/ScreenshotsComponentChild.sys.mjs +++ b/browser/actors/ScreenshotsComponentChild.sys.mjs @@ -83,8 +83,11 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { // Handle overlay events here if ( - ScreenshotsComponentChild.OVERLAY_EVENTS.includes(event.type) || - ScreenshotsComponentChild.PREVENTABLE_EVENTS.includes(event.type) + [ + ...ScreenshotsComponentChild.OVERLAY_EVENTS, + ...ScreenshotsComponentChild.PREVENTABLE_EVENTS, + "selectionchange", + ].includes(event.type) ) { if (!this.overlay?.initialized) { return; diff --git a/browser/components/screenshots/tests/browser/browser_text_selectionAPI_test.js b/browser/components/screenshots/tests/browser/browser_text_selectionAPI_test.js index 78764d384725..ed8ec6f3268f 100644 --- a/browser/components/screenshots/tests/browser/browser_text_selectionAPI_test.js +++ b/browser/components/screenshots/tests/browser/browser_text_selectionAPI_test.js @@ -27,6 +27,15 @@ add_task(async function test_textSelectedDuringScreenshot() { await helper.clickTestPageElement("selection"); + // The selection doesn't get cleared in the tests so just manually + // remove the selection here. + // In real scenarios, the selection is cleared when the page is + // interacted with. + await ContentTask.spawn(browser, [], async () => { + let selection = content.window.getSelection(); + selection.removeAllRanges(); + }); + let clipboardChanged = helper.waitForRawClipboardChange( Math.round(rect.width), Math.round(rect.height),