Innovenergy_trunk/frontend/node_modules/testcafe-browser-tools/lib/api/find-window.js

69 lines
7.1 KiB
JavaScript

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const os_family_1 = __importDefault(require("os-family"));
const os_1 = require("os");
const exec_1 = require("../utils/exec");
const binaries_1 = __importDefault(require("../binaries"));
const EXIT_CODES = __importStar(require("../exit-codes"));
const errors_1 = require("../errors");
/**
* Retrieves a platform-specific window descriptor for the window that contains a web page with the specified title.
* @function
* @async
* @name findWindow
* @param {string} pageTitle - The title of the web page opened in a window whose descriptor should be retrieved.
* @returns {object} a platform-specific window descriptor that can be used as a window identifier.
**/
async function runFindWindowBinary(pageTitle) {
try {
return await exec_1.execFile(binaries_1.default.findWindow, [pageTitle]);
}
catch (err) {
if (!(err instanceof errors_1.NativeBinaryHasFailedError))
throw err;
if (err.data.exitCode === EXIT_CODES.WINDOW_NOT_FOUND)
return null;
if (err.data.exitCode === EXIT_CODES.DISPLAY_NOT_FOUND)
throw new errors_1.UnableToOpenDisplayError(err.data);
if (os_family_1.default.mac && err.data.exitCode === EXIT_CODES.PERMISSION_ERROR)
throw new errors_1.UnableToAccessScreenRecordingAPIError(err.data);
throw err;
}
}
async function default_1(pageTitle) {
var res = await runFindWindowBinary(pageTitle);
if (!res)
return res;
var windowParams = res.split(os_1.EOL);
if (os_family_1.default.win)
return { hwnd: windowParams[0], browser: windowParams[1] };
if (os_family_1.default.mac)
return { processId: windowParams[0], cocoaId: windowParams[1], windowId: windowParams[2] };
if (os_family_1.default.linux)
return { windowId: windowParams[0] };
return null;
}
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmluZC13aW5kb3cuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXBpL2ZpbmQtd2luZG93LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDBEQUEyQjtBQUMzQiwyQkFBeUI7QUFDekIsd0NBQXlDO0FBQ3pDLDJEQUFtQztBQUNuQywwREFBNEM7QUFDNUMsc0NBSW1CO0FBR25COzs7Ozs7O0lBT0k7QUFDSixLQUFLLFVBQVUsbUJBQW1CLENBQUUsU0FBUztJQUN6QyxJQUFJO1FBQ0EsT0FBTyxNQUFNLGVBQVEsQ0FBQyxrQkFBUSxDQUFDLFVBQVUsRUFBRSxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUM7S0FDM0Q7SUFDRCxPQUFPLEdBQUcsRUFBRTtRQUNSLElBQUksQ0FBQyxDQUFDLEdBQUcsWUFBWSxtQ0FBMEIsQ0FBQztZQUM1QyxNQUFNLEdBQUcsQ0FBQztRQUVkLElBQUksR0FBRyxDQUFDLElBQUksQ0FBQyxRQUFRLEtBQUssVUFBVSxDQUFDLGdCQUFnQjtZQUNqRCxPQUFPLElBQUksQ0FBQztRQUVoQixJQUFJLEdBQUcsQ0FBQyxJQUFJLENBQUMsUUFBUSxLQUFLLFVBQVUsQ0FBQyxpQkFBaUI7WUFDbEQsTUFBTSxJQUFJLGlDQUF3QixDQUFDLEdBQUcsQ0FB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