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.

switchWindow.js 1012B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. async function switchWindow(urlOrTitleToMatch) {
  4. if (typeof urlOrTitleToMatch !== 'string' && !(urlOrTitleToMatch instanceof RegExp)) {
  5. throw new Error('Unsupported parameter for switchWindow, required is "string" or an RegExp');
  6. }
  7. const tabs = await this.getWindowHandles();
  8. const matchesTarget = (target) => {
  9. if (typeof urlOrTitleToMatch === 'string') {
  10. return target.includes(urlOrTitleToMatch);
  11. }
  12. return !!target.match(urlOrTitleToMatch);
  13. };
  14. for (const tab of tabs) {
  15. await this.switchToWindow(tab);
  16. const url = await this.getUrl();
  17. if (matchesTarget(url)) {
  18. return tab;
  19. }
  20. const title = await this.getTitle();
  21. if (matchesTarget(title)) {
  22. return tab;
  23. }
  24. }
  25. throw new Error(`No window found with title or url matching "${urlOrTitleToMatch}"`);
  26. }
  27. exports.default = switchWindow;