From 6ef703115e29b558f0fdf29d9bcaa5383741268d Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Fri, 29 Jan 2021 15:05:05 +0000 Subject: [PATCH] Bug 1689548 - [devtools] Don't simulate flash on screenshot when prefers-reduced-motion is enabled. r=ladybenko. We also take this opportunity to simplify the simulateCameraFlash function by using a simpler version of element.animate. Differential Revision: https://phabricator.services.mozilla.com/D103457 --- .../server/actors/utils/capture-screenshot.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/devtools/server/actors/utils/capture-screenshot.js b/devtools/server/actors/utils/capture-screenshot.js index 41a0aad4c956..db62f2179136 100644 --- a/devtools/server/actors/utils/capture-screenshot.js +++ b/devtools/server/actors/utils/capture-screenshot.js @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; -const { Cu, Cc, Ci } = require("chrome"); +const { Cc, Ci } = require("chrome"); const Services = require("Services"); const { LocalizationHelper } = require("devtools/shared/l10n"); @@ -26,9 +26,16 @@ const MAX_IMAGE_HEIGHT = 10000; * The target document. */ function simulateCameraFlash(document) { - const window = document.defaultView; - const frames = Cu.cloneInto({ opacity: [0, 1] }, window); - document.documentElement.animate(frames, CONTAINER_FLASHING_DURATION); + const node = document.documentElement; + + // Don't take a screenshot if the user prefers reduced motion. + if (node.ownerGlobal.matchMedia("(prefers-reduced-motion)").matches) { + return; + } + + node.animate([{ opacity: 0 }, { opacity: 1 }], { + duration: CONTAINER_FLASHING_DURATION, + }); } /**