playwright.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Playwright = void 0;
  6. exports.createPlaywright = createPlaywright;
  7. var _android = require("./android/android");
  8. var _backendAdb = require("./android/backendAdb");
  9. var _chromium = require("./chromium/chromium");
  10. var _electron = require("./electron/electron");
  11. var _firefox = require("./firefox/firefox");
  12. var _selectors = require("./selectors");
  13. var _webkit = require("./webkit/webkit");
  14. var _instrumentation = require("./instrumentation");
  15. var _debugLogger = require("../common/debugLogger");
  16. var _debugController = require("./debugController");
  17. /**
  18. * Copyright (c) Microsoft Corporation.
  19. *
  20. * Licensed under the Apache License, Version 2.0 (the "License");
  21. * you may not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at
  23. *
  24. * http://www.apache.org/licenses/LICENSE-2.0
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an "AS IS" BASIS,
  28. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. */
  32. class Playwright extends _instrumentation.SdkObject {
  33. constructor(options) {
  34. super({
  35. attribution: {},
  36. instrumentation: (0, _instrumentation.createInstrumentation)()
  37. }, undefined, 'Playwright');
  38. this.selectors = void 0;
  39. this.chromium = void 0;
  40. this.android = void 0;
  41. this.electron = void 0;
  42. this.firefox = void 0;
  43. this.webkit = void 0;
  44. this.options = void 0;
  45. this.debugController = void 0;
  46. this._allPages = new Set();
  47. this._allBrowsers = new Set();
  48. this.options = options;
  49. this.attribution.playwright = this;
  50. this.instrumentation.addListener({
  51. onBrowserOpen: browser => this._allBrowsers.add(browser),
  52. onBrowserClose: browser => this._allBrowsers.delete(browser),
  53. onPageOpen: page => this._allPages.add(page),
  54. onPageClose: page => this._allPages.delete(page),
  55. onCallLog: (sdkObject, metadata, logName, message) => {
  56. _debugLogger.debugLogger.log(logName, message);
  57. }
  58. }, null);
  59. this.chromium = new _chromium.Chromium(this);
  60. this.firefox = new _firefox.Firefox(this);
  61. this.webkit = new _webkit.WebKit(this);
  62. this.electron = new _electron.Electron(this);
  63. this.android = new _android.Android(this, new _backendAdb.AdbBackend());
  64. this.selectors = new _selectors.Selectors();
  65. this.debugController = new _debugController.DebugController(this);
  66. }
  67. async hideHighlight() {
  68. await Promise.all([...this._allPages].map(p => p.hideHighlight().catch(() => {})));
  69. }
  70. allBrowsers() {
  71. return [...this._allBrowsers];
  72. }
  73. allPages() {
  74. return [...this._allPages];
  75. }
  76. }
  77. exports.Playwright = Playwright;
  78. function createPlaywright(options) {
  79. return new Playwright(options);
  80. }