screenshot.js (1016B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { 8 TAKE_SCREENSHOT_START, 9 TAKE_SCREENSHOT_END, 10 } = require("resource://devtools/client/responsive/actions/index.js"); 11 12 const message = require("resource://devtools/client/responsive/utils/message.js"); 13 14 const animationFrame = () => 15 new Promise(resolve => { 16 window.requestAnimationFrame(resolve); 17 }); 18 19 module.exports = { 20 takeScreenshot() { 21 return async function ({ dispatch }) { 22 await dispatch({ type: TAKE_SCREENSHOT_START }); 23 24 // Waiting the next repaint, to ensure the react components 25 // can be properly render after the action dispatched above 26 await animationFrame(); 27 28 window.postMessage({ type: "screenshot" }, "*"); 29 await message.wait(window, "screenshot-captured"); 30 31 dispatch({ type: TAKE_SCREENSHOT_END }); 32 }; 33 }, 34 };