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.

index.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. exports.SUPPORTED_BROWSER = exports.sessionMap = void 0;
  7. const os_1 = __importDefault(require("os"));
  8. const path_1 = __importDefault(require("path"));
  9. const ua_parser_js_1 = __importDefault(require("ua-parser-js"));
  10. const uuid_1 = require("uuid");
  11. const logger_1 = __importDefault(require("@wdio/logger"));
  12. const utils_1 = require("@wdio/utils");
  13. const config_1 = require("@wdio/config");
  14. const devtoolsdriver_1 = __importDefault(require("./devtoolsdriver"));
  15. const launcher_1 = __importDefault(require("./launcher"));
  16. const constants_1 = require("./constants");
  17. Object.defineProperty(exports, "SUPPORTED_BROWSER", { enumerable: true, get: function () { return constants_1.SUPPORTED_BROWSER; } });
  18. const utils_2 = require("./utils");
  19. const log = logger_1.default('devtools:puppeteer');
  20. utils_2.patchDebug(log);
  21. exports.sessionMap = new Map();
  22. class DevTools {
  23. static async newSession(options = {}, modifier, userPrototype = {}, customCommandWrapper) {
  24. var _a, _b;
  25. const params = config_1.validateConfig(constants_1.DEFAULTS, options);
  26. if (params.logLevel && (!options.logLevels || !options.logLevels['devtools'])) {
  27. logger_1.default.setLevel('devtools', params.logLevel);
  28. }
  29. if (params.outputDir && !process.env.WDIO_LOG_PATH) {
  30. process.env.WDIO_LOG_PATH = path_1.default.join(params.outputDir, 'wdio.log');
  31. }
  32. log.info('Initiate new session using the DevTools protocol');
  33. const browser = await launcher_1.default(params.capabilities);
  34. const pages = await browser.pages();
  35. const driver = new devtoolsdriver_1.default(browser, pages);
  36. const sessionId = uuid_1.v4();
  37. const uaParser = new ua_parser_js_1.default(await browser.userAgent());
  38. const userAgent = uaParser.getResult();
  39. const availableVendorPrefixes = Object.values(constants_1.VENDOR_PREFIX);
  40. const vendorCapPrefix = Object.keys(params.capabilities)
  41. .find((capKey) => availableVendorPrefixes.includes(capKey));
  42. params.requestedCapabilities = { ...params.capabilities };
  43. params.capabilities = {
  44. browserName: userAgent.browser.name,
  45. browserVersion: userAgent.browser.version,
  46. platformName: os_1.default.platform(),
  47. platformVersion: os_1.default.release()
  48. };
  49. if (vendorCapPrefix) {
  50. Object.assign(params.capabilities, {
  51. [vendorCapPrefix]: Object.assign({ debuggerAddress: browser._connection.url().split('/')[2] }, params.capabilities[vendorCapPrefix])
  52. });
  53. }
  54. exports.sessionMap.set(sessionId, { browser, session: driver });
  55. const environmentPrototype = { puppeteer: { value: browser } };
  56. Object.entries(utils_1.devtoolsEnvironmentDetector({
  57. browserName: (_b = (_a = userAgent === null || userAgent === void 0 ? void 0 : userAgent.browser) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()
  58. })).forEach(([name, value]) => {
  59. environmentPrototype[name] = { value };
  60. });
  61. const commandWrapper = (method, endpoint, commandInfo) => driver.register(commandInfo);
  62. const protocolCommands = utils_2.getPrototype(commandWrapper);
  63. const prototype = {
  64. ...protocolCommands,
  65. ...userPrototype,
  66. ...environmentPrototype
  67. };
  68. const monad = utils_1.webdriverMonad(params, modifier, prototype);
  69. return monad(sessionId, customCommandWrapper);
  70. }
  71. static async reloadSession(instance) {
  72. const { session } = exports.sessionMap.get(instance.sessionId);
  73. const browser = await launcher_1.default(instance.requestedCapabilities);
  74. const pages = await browser.pages();
  75. session.elementStore.clear();
  76. session.windows = new Map();
  77. session.browser = browser;
  78. for (const page of pages) {
  79. const pageId = uuid_1.v4();
  80. session.windows.set(pageId, page);
  81. session.currentWindowHandle = pageId;
  82. }
  83. exports.sessionMap.set(instance.sessionId, { browser, session });
  84. return instance.sessionId;
  85. }
  86. static attachToSession() {
  87. throw new Error('not yet implemented');
  88. }
  89. }
  90. exports.default = DevTools;