playwright.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Playwright = void 0;
  6. var _errors = require("./errors");
  7. var _android = require("./android");
  8. var _browserType = require("./browserType");
  9. var _channelOwner = require("./channelOwner");
  10. var _electron = require("./electron");
  11. var _fetch = require("./fetch");
  12. var _selectors = require("./selectors");
  13. /**
  14. * Copyright (c) Microsoft Corporation.
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. class Playwright extends _channelOwner.ChannelOwner {
  29. constructor(parent, type, guid, initializer) {
  30. var _this$_connection$loc, _this$_connection$loc2;
  31. super(parent, type, guid, initializer);
  32. this._android = void 0;
  33. this._electron = void 0;
  34. this.chromium = void 0;
  35. this.firefox = void 0;
  36. this.webkit = void 0;
  37. this.devices = void 0;
  38. this.selectors = void 0;
  39. this.request = void 0;
  40. this.errors = void 0;
  41. this.request = new _fetch.APIRequest(this);
  42. this.chromium = _browserType.BrowserType.from(initializer.chromium);
  43. this.chromium._playwright = this;
  44. this.firefox = _browserType.BrowserType.from(initializer.firefox);
  45. this.firefox._playwright = this;
  46. this.webkit = _browserType.BrowserType.from(initializer.webkit);
  47. this.webkit._playwright = this;
  48. this._android = _android.Android.from(initializer.android);
  49. this._electron = _electron.Electron.from(initializer.electron);
  50. this.devices = (_this$_connection$loc = (_this$_connection$loc2 = this._connection.localUtils()) === null || _this$_connection$loc2 === void 0 ? void 0 : _this$_connection$loc2.devices) !== null && _this$_connection$loc !== void 0 ? _this$_connection$loc : {};
  51. this.selectors = new _selectors.Selectors();
  52. this.errors = {
  53. TimeoutError: _errors.TimeoutError
  54. };
  55. const selectorsOwner = _selectors.SelectorsOwner.from(initializer.selectors);
  56. this.selectors._addChannel(selectorsOwner);
  57. this._connection.on('close', () => {
  58. this.selectors._removeChannel(selectorsOwner);
  59. });
  60. global._playwrightInstance = this;
  61. }
  62. _setSelectors(selectors) {
  63. const selectorsOwner = _selectors.SelectorsOwner.from(this._initializer.selectors);
  64. this.selectors._removeChannel(selectorsOwner);
  65. this.selectors = selectors;
  66. this.selectors._addChannel(selectorsOwner);
  67. }
  68. static from(channel) {
  69. return channel._object;
  70. }
  71. }
  72. exports.Playwright = Playwright;