chromeless
Version:
🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
738 lines • 36 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("../util");
var LocalRuntime = /** @class */ (function () {
function LocalRuntime(client, chromelessOptions) {
this.client = client;
this.chromelessOptions = chromelessOptions;
}
LocalRuntime.prototype.run = function (command) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (command.type) {
case 'goto':
return [2 /*return*/, this.goto(command.url, command.timeout)];
case 'setViewport':
return [2 /*return*/, util_1.setViewport(this.client, command.options)];
case 'wait': {
if (command.selector) {
return [2 /*return*/, this.waitSelector(command.selector, command.timeout)];
}
else if (command.timeout) {
return [2 /*return*/, this.waitTimeout(command.timeout)];
}
else {
throw new Error('waitFn not yet implemented');
}
}
case 'clearCache':
return [2 /*return*/, this.clearCache()];
case 'clearStorage':
return [2 /*return*/, this.clearStorage(command.origin, command.storageTypes)];
case 'setUserAgent':
return [2 /*return*/, this.setUserAgent(command.useragent)];
case 'click':
return [2 /*return*/, this.click(command.selector)];
case 'returnCode':
return [2 /*return*/, this.returnCode.apply(this, [command.fn].concat(command.args))];
case 'returnExists':
return [2 /*return*/, this.returnExists(command.selector)];
case 'returnScreenshot':
return [2 /*return*/, this.returnScreenshot(command.selector, command.options)];
case 'returnHtml':
return [2 /*return*/, this.returnHtml()];
case 'returnHtmlUrl':
return [2 /*return*/, this.returnHtmlUrl()];
case 'returnPdf':
return [2 /*return*/, this.returnPdf(command.options)];
case 'returnInputValue':
return [2 /*return*/, this.returnInputValue(command.selector)];
case 'type':
return [2 /*return*/, this.type(command.input, command.selector)];
case 'press':
return [2 /*return*/, this.press(command.keyCode, command.count, command.modifiers)];
case 'scrollTo':
return [2 /*return*/, this.scrollTo(command.x, command.y)];
case 'scrollToElement':
return [2 /*return*/, this.scrollToElement(command.selector)];
case 'deleteCookies':
return [2 /*return*/, this.deleteCookies(command.name, command.url)];
case 'clearCookies':
return [2 /*return*/, this.clearCookies()];
case 'setHtml':
return [2 /*return*/, this.setHtml(command.html)];
case 'setExtraHTTPHeaders':
return [2 /*return*/, this.setExtraHTTPHeaders(command.headers)];
case 'cookies':
return [2 /*return*/, this.cookies(command.nameOrQuery)];
case 'allCookies':
return [2 /*return*/, this.allCookies()];
case 'setCookies':
return [2 /*return*/, this.setCookies(command.nameOrCookies, command.value)];
case 'mousedown':
return [2 /*return*/, this.mousedown(command.selector)];
case 'mouseup':
return [2 /*return*/, this.mouseup(command.selector)];
case 'focus':
return [2 /*return*/, this.focus(command.selector)];
case 'clearInput':
return [2 /*return*/, this.clearInput(command.selector)];
case 'setFileInput':
return [2 /*return*/, this.setFileInput(command.selector, command.files)];
default:
throw new Error("No such command: " + JSON.stringify(command));
}
return [2 /*return*/];
});
});
};
LocalRuntime.prototype.goto = function (url, waitTimeout) {
if (waitTimeout === void 0) { waitTimeout = this.chromelessOptions.waitTimeout; }
return __awaiter(this, void 0, void 0, function () {
var _a, Network, Page, e2p;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.client, Network = _a.Network, Page = _a.Page;
return [4 /*yield*/, Promise.all([Network.enable(), Page.enable()])];
case 1:
_b.sent();
if (!this.userAgentValue)
this.userAgentValue = "Chromeless " + util_1.version;
return [4 /*yield*/, Network.setUserAgentOverride({ userAgent: this.userAgentValue })];
case 2:
_b.sent();
e2p = util_1.eventToPromise();
Page.loadEventFired(e2p.onEvent);
return [4 /*yield*/, Page.navigate({ url: url })];
case 3:
_b.sent();
return [4 /*yield*/, util_1.waitForPromise(e2p.fired(), waitTimeout, 'page load event')];
case 4:
_b.sent();
this.log("Navigated to " + url);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.clearCache = function () {
return __awaiter(this, void 0, void 0, function () {
var Network, canClearCache;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Network = this.client.Network;
return [4 /*yield*/, Network.canClearBrowserCache];
case 1:
canClearCache = _a.sent();
if (!canClearCache) return [3 /*break*/, 3];
return [4 /*yield*/, Network.clearBrowserCache()];
case 2:
_a.sent();
this.log("Cache is cleared");
return [3 /*break*/, 4];
case 3:
this.log("Cache could not be cleared");
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.clearStorage = function (origin, storageTypes) {
return __awaiter(this, void 0, void 0, function () {
var _a, Storage, Network, canClearCache;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.client, Storage = _a.Storage, Network = _a.Network;
return [4 /*yield*/, Network.canClearBrowserCache];
case 1:
canClearCache = _b.sent();
if (!canClearCache) return [3 /*break*/, 3];
return [4 /*yield*/, Storage.clearDataForOrigin({ origin: origin, storageTypes: storageTypes })];
case 2:
_b.sent();
this.log(storageTypes + " for " + origin + " is cleared");
return [3 /*break*/, 4];
case 3:
this.log(storageTypes + " could not be cleared");
_b.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.setUserAgent = function (useragent) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.userAgentValue = useragent;
return [4 /*yield*/, this.log("Set useragent to " + this.userAgentValue)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.waitTimeout = function (timeout) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.log("Waiting for " + timeout + "ms");
return [4 /*yield*/, util_1.wait(timeout)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.waitSelector = function (selector, waitTimeout) {
if (waitTimeout === void 0) { waitTimeout = this.chromelessOptions.waitTimeout; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.log("Waiting for " + selector + " " + waitTimeout);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, waitTimeout)];
case 1:
_a.sent();
this.log("Waited for " + selector);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.click = function (selector) {
return __awaiter(this, void 0, void 0, function () {
var exists, scale;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("click(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("click(): node for selector " + selector + " doesn't exist");
}
scale = this.chromelessOptions.viewport.scale;
if (!this.chromelessOptions.scrollBeforeClick) return [3 /*break*/, 5];
return [4 /*yield*/, util_1.scrollToElement(this.client, selector)];
case 4:
_a.sent();
_a.label = 5;
case 5: return [4 /*yield*/, util_1.click(this.client, selector, scale)];
case 6:
_a.sent();
this.log("Clicked on " + selector);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.returnCode = function (fn) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.evaluate.apply(void 0, [this.client, fn].concat(args))];
case 1: return [2 /*return*/, (_a.sent())];
}
});
});
};
LocalRuntime.prototype.scrollTo = function (x, y) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, util_1.scrollTo(this.client, x, y)];
});
});
};
LocalRuntime.prototype.scrollToElement = function (selector) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("scrollToElement(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2 /*return*/, util_1.scrollToElement(this.client, selector)];
}
});
});
};
LocalRuntime.prototype.mousedown = function (selector) {
return __awaiter(this, void 0, void 0, function () {
var exists, scale;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("mousedown(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("mousedown(): node for selector " + selector + " doesn't exist");
}
scale = this.chromelessOptions.viewport.scale;
return [4 /*yield*/, util_1.mousedown(this.client, selector, scale)];
case 4:
_a.sent();
this.log("Mousedown on " + selector);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.mouseup = function (selector) {
return __awaiter(this, void 0, void 0, function () {
var exists, scale;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("mouseup(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("mouseup(): node for selector " + selector + " doesn't exist");
}
scale = this.chromelessOptions.viewport.scale;
return [4 /*yield*/, util_1.mouseup(this.client, selector, scale)];
case 4:
_a.sent();
this.log("Mouseup on " + selector);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.setHtml = function (html) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.setHtml(this.client, html)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.focus = function (selector) {
return __awaiter(this, void 0, void 0, function () {
var exists;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("focus(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("focus(): node for selector " + selector + " doesn't exist");
}
return [4 /*yield*/, util_1.focus(this.client, selector)];
case 4:
_a.sent();
this.log("Focus on " + selector);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.type = function (text, selector) {
return __awaiter(this, void 0, void 0, function () {
var exists;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!selector) return [3 /*break*/, 4];
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("type(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("type(): Node not found for selector: " + selector);
}
_a.label = 4;
case 4: return [4 /*yield*/, util_1.type(this.client, text, selector)];
case 5:
_a.sent();
this.log("Typed " + text + " in " + selector);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.cookies = function (nameOrQuery) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.getCookies(this.client, nameOrQuery)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
LocalRuntime.prototype.allCookies = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.getAllCookies(this.client)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
LocalRuntime.prototype.setExtraHTTPHeaders = function (headers) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.setExtraHTTPHeaders(this.client, headers)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
LocalRuntime.prototype.setCookies = function (nameOrCookies, value) {
return __awaiter(this, void 0, void 0, function () {
var cookies, fn, url, cookie;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(typeof nameOrCookies !== 'string' && !value)) return [3 /*break*/, 2];
cookies = Array.isArray(nameOrCookies)
? nameOrCookies
: [nameOrCookies];
return [4 /*yield*/, util_1.setCookies(this.client, cookies)];
case 1: return [2 /*return*/, _a.sent()];
case 2:
if (!(typeof nameOrCookies === 'string' && typeof value === 'string')) return [3 /*break*/, 5];
fn = function () { return location.href; };
return [4 /*yield*/, util_1.evaluate(this.client, "" + fn)];
case 3:
url = (_a.sent());
cookie = {
url: url,
name: nameOrCookies,
value: value,
};
return [4 /*yield*/, util_1.setCookies(this.client, [cookie])];
case 4: return [2 /*return*/, _a.sent()];
case 5: throw new Error("setCookies(): Invalid input " + nameOrCookies + ", " + value);
}
});
});
};
LocalRuntime.prototype.deleteCookies = function (name, url) {
return __awaiter(this, void 0, void 0, function () {
var Network, canClearCookies;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Network = this.client.Network;
return [4 /*yield*/, Network.canClearBrowserCookies()];
case 1:
canClearCookies = _a.sent();
if (!canClearCookies) return [3 /*break*/, 3];
return [4 /*yield*/, util_1.deleteCookie(this.client, name, url)];
case 2:
_a.sent();
this.log("Cookie " + name + " cleared");
return [3 /*break*/, 4];
case 3:
this.log("Cookie " + name + " could not be cleared");
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.clearCookies = function () {
return __awaiter(this, void 0, void 0, function () {
var Network, canClearCookies;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Network = this.client.Network;
return [4 /*yield*/, Network.canClearBrowserCookies()];
case 1:
canClearCookies = _a.sent();
if (!canClearCookies) return [3 /*break*/, 3];
return [4 /*yield*/, util_1.clearCookies(this.client)];
case 2:
_a.sent();
this.log('Cookies cleared');
return [3 /*break*/, 4];
case 3:
this.log('Cookies could not be cleared');
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.press = function (keyCode, count, modifiers) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.log("Sending keyCode " + keyCode + " (modifiers: " + modifiers + ")");
return [4 /*yield*/, util_1.press(this.client, keyCode, count, modifiers)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.returnExists = function (selector) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
LocalRuntime.prototype.returnInputValue = function (selector) {
return __awaiter(this, void 0, void 0, function () {
var exists;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 1:
exists = _a.sent();
if (!exists) {
throw new Error("value: node for selector " + selector + " doesn't exist");
}
return [2 /*return*/, util_1.getValue(this.client, selector)];
}
});
});
};
// Returns the S3 url or local file path
LocalRuntime.prototype.returnScreenshot = function (selector, options) {
return __awaiter(this, void 0, void 0, function () {
var exists, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!selector) return [3 /*break*/, 4];
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("screenshot(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("screenshot(): node for selector " + selector + " doesn't exist");
}
_a.label = 4;
case 4: return [4 /*yield*/, util_1.screenshot(this.client, selector)];
case 5:
data = _a.sent();
if (!util_1.isS3Configured()) return [3 /*break*/, 7];
return [4 /*yield*/, util_1.uploadToS3(data, 'image/png')];
case 6: return [2 /*return*/, _a.sent()];
case 7: return [2 /*return*/, util_1.writeToFile(data, 'png', options && options.filePath)];
}
});
});
};
LocalRuntime.prototype.returnHtml = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.html(this.client)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
LocalRuntime.prototype.returnHtmlUrl = function (options) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, util_1.html(this.client)];
case 1:
data = _a.sent();
if (!util_1.isS3Configured()) return [3 /*break*/, 3];
return [4 /*yield*/, util_1.uploadToS3(data, 'text/html')];
case 2: return [2 /*return*/, _a.sent()];
case 3: return [2 /*return*/, util_1.writeToFile(data, 'html', options && options.filePath)];
}
});
});
};
// Returns the S3 url or local file path
LocalRuntime.prototype.returnPdf = function (options) {
return __awaiter(this, void 0, void 0, function () {
var _a, filePath, cdpOptions, data;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = options || { filePath: undefined }, filePath = _a.filePath, cdpOptions = __rest(_a, ["filePath"]);
return [4 /*yield*/, util_1.pdf(this.client, cdpOptions)];
case 1:
data = _b.sent();
if (!util_1.isS3Configured()) return [3 /*break*/, 3];
return [4 /*yield*/, util_1.uploadToS3(data, 'application/pdf')];
case 2: return [2 /*return*/, _b.sent()];
case 3: return [2 /*return*/, util_1.writeToFile(data, 'pdf', filePath)];
}
});
});
};
LocalRuntime.prototype.clearInput = function (selector) {
return __awaiter(this, void 0, void 0, function () {
var exists;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!selector) return [3 /*break*/, 4];
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("clearInput(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("clearInput(): Node not found for selector: " + selector);
}
_a.label = 4;
case 4: return [4 /*yield*/, util_1.clearInput(this.client, selector)];
case 5:
_a.sent();
this.log(selector + " cleared");
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.setFileInput = function (selector, files) {
return __awaiter(this, void 0, void 0, function () {
var exists;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.chromelessOptions.implicitWait) return [3 /*break*/, 2];
this.log("setFileInput(): Waiting for " + selector);
return [4 /*yield*/, util_1.waitForNode(this.client, selector, this.chromelessOptions.waitTimeout)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, util_1.nodeExists(this.client, selector)];
case 3:
exists = _a.sent();
if (!exists) {
throw new Error("setFileInput(): node for selector " + selector + " doesn't exist");
}
return [4 /*yield*/, util_1.setFileInput(this.client, selector, files)];
case 4:
_a.sent();
this.log("setFileInput() files " + files);
return [2 /*return*/];
}
});
});
};
LocalRuntime.prototype.log = function (msg) {
if (this.chromelessOptions.debug) {
console.log(msg);
}
};
return LocalRuntime;
}());
exports.default = LocalRuntime;
//# sourceMappingURL=local-runtime.js.map