Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

executeScript.js 1.5KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const executeScript_1 = __importDefault(require("../scripts/executeScript"));
  7. const utils_1 = require("../utils");
  8. const constants_1 = require("../constants");
  9. async function executeScript({ script, args }) {
  10. const page = this.getPageHandle(true);
  11. const scriptTimeout = this.timeouts.get('script');
  12. script = script.trim();
  13. if (script.startsWith('return (')) {
  14. script = script.slice(7);
  15. }
  16. if (script.startsWith('return')) {
  17. script = `(function () { ${script} }).apply(null, arguments)`;
  18. }
  19. const executePromise = page.$eval('html', executeScript_1.default, script, constants_1.SERIALIZE_PROPERTY, constants_1.SERIALIZE_FLAG, ...(await utils_1.transformExecuteArgs.call(this, args)));
  20. let executeTimeout;
  21. const timeoutPromise = new Promise((_, reject) => {
  22. executeTimeout = setTimeout(() => {
  23. const timeoutError = `script timeout${this.activeDialog
  24. ? ' reason: a browser dialog has opened as result of a executeScript call'
  25. : ''}`;
  26. return reject(new Error(timeoutError));
  27. }, scriptTimeout);
  28. });
  29. const result = await Promise.race([executePromise, timeoutPromise]);
  30. clearTimeout(executeTimeout);
  31. return utils_1.transformExecuteResult.call(this, page, result);
  32. }
  33. exports.default = executeScript;