29 lines
3.9 KiB
JavaScript
29 lines
3.9 KiB
JavaScript
|
"use strict";
|
||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
const find_window_1 = __importDefault(require("./find-window"));
|
||
|
const get_window_size_1 = __importDefault(require("./get-window-size"));
|
||
|
const delay_1 = __importDefault(require("../utils/delay"));
|
||
|
const DEFAULT_WATCHING_INTERVAL = 2000;
|
||
|
/**
|
||
|
* Pause execution of a Promise chain while the specified browser window is opened.
|
||
|
* @function
|
||
|
* @name watchWindow
|
||
|
* @param {string | object} windowDescriptor - The title of the web page opened in the window or a descriptor returned by findWindow
|
||
|
* @param {number} [watchingInterval=2000] - A time interval in milliseconds between checking the window state
|
||
|
* @returns Promise<undefined> A Promise which resolves when the browser window is closed.
|
||
|
**/
|
||
|
async function default_1(windowDescriptor, watchingInterval = DEFAULT_WATCHING_INTERVAL) {
|
||
|
var windowDescription = typeof windowDescriptor === 'string' ? await find_window_1.default(windowDescriptor) : windowDescriptor;
|
||
|
if (!windowDescription)
|
||
|
return;
|
||
|
var windowSize = await get_window_size_1.default(windowDescription);
|
||
|
while (windowSize && windowSize.width && windowSize.height) {
|
||
|
await delay_1.default(watchingInterval);
|
||
|
windowSize = await get_window_size_1.default(windowDescription);
|
||
|
}
|
||
|
}
|
||
|
exports.default = default_1;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2F0Y2gtd2luZG93LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwaS93YXRjaC13aW5kb3cuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxnRUFBdUM7QUFDdkMsd0VBQThDO0FBQzlDLDJEQUFtQztBQUduQyxNQUFNLHlCQUF5QixHQUFHLElBQUksQ0FBQztBQUV2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