appium-remote-debugger
Version:
Appium proxy for Remote Debugger protocol
35 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.captureScreenshot = captureScreenshot;
const property_accessors_1 = require("./property-accessors");
/**
* Captures a screenshot of a rectangular area of the page or the entire viewport.
* If no rectangle is provided, captures the full viewport by default.
*
* @param opts - Screenshot capture options. If not provided, captures the entire viewport.
* - rect: The rectangle to capture. If null, captures the whole viewport.
* - coordinateSystem: The coordinate system to use ('Viewport' or 'Page').
* Defaults to 'Viewport'.
* @returns A promise that resolves to a base64-encoded string of the screenshot
* (without the data URL prefix).
*/
async function captureScreenshot(opts = {}) {
const { rect = null, coordinateSystem = 'Viewport' } = opts;
this.log.debug('Capturing screenshot');
const arect = rect ??
(await this.executeAtom('execute_script', [
'return {x: 0, y: 0, width: window.innerWidth, height: window.innerHeight}',
[],
]));
const response = await this.requireRpcClient().send('Page.snapshotRect', {
...arect,
appIdKey: (0, property_accessors_1.getAppIdKey)(this),
pageIdKey: (0, property_accessors_1.getPageIdKey)(this),
coordinateSystem,
});
if (response.error) {
throw new Error(response.error);
}
return response.dataURL.replace(/^data:image\/png;base64,/, '');
}
//# sourceMappingURL=screenshot.js.map