playwrightDispatcher.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.PlaywrightDispatcher = void 0;
  6. var _fetch = require("../fetch");
  7. var _socksProxy = require("../../common/socksProxy");
  8. var _androidDispatcher = require("./androidDispatcher");
  9. var _browserTypeDispatcher = require("./browserTypeDispatcher");
  10. var _dispatcher = require("./dispatcher");
  11. var _electronDispatcher = require("./electronDispatcher");
  12. var _localUtilsDispatcher = require("./localUtilsDispatcher");
  13. var _networkDispatchers = require("./networkDispatchers");
  14. var _selectorsDispatcher = require("./selectorsDispatcher");
  15. var _browserDispatcher = require("./browserDispatcher");
  16. var _utils = require("../../utils");
  17. var _eventsHelper = require("../../utils/eventsHelper");
  18. /**
  19. * Copyright (c) Microsoft Corporation.
  20. *
  21. * Licensed under the Apache License, Version 2.0 (the 'License");
  22. * you may not use this file except in compliance with the License.
  23. * You may obtain a copy of the License at
  24. *
  25. * http://www.apache.org/licenses/LICENSE-2.0
  26. *
  27. * Unless required by applicable law or agreed to in writing, software
  28. * distributed under the License is distributed on an "AS IS" BASIS,
  29. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  30. * See the License for the specific language governing permissions and
  31. * limitations under the License.
  32. */
  33. class PlaywrightDispatcher extends _dispatcher.Dispatcher {
  34. constructor(scope, playwright, socksProxy, preLaunchedBrowser, prelaunchedAndroidDevice) {
  35. const browserDispatcher = preLaunchedBrowser ? new _browserDispatcher.ConnectedBrowserDispatcher(scope, preLaunchedBrowser) : undefined;
  36. const android = new _androidDispatcher.AndroidDispatcher(scope, playwright.android);
  37. const prelaunchedAndroidDeviceDispatcher = prelaunchedAndroidDevice ? new _androidDispatcher.AndroidDeviceDispatcher(android, prelaunchedAndroidDevice) : undefined;
  38. super(scope, playwright, 'Playwright', {
  39. chromium: new _browserTypeDispatcher.BrowserTypeDispatcher(scope, playwright.chromium),
  40. firefox: new _browserTypeDispatcher.BrowserTypeDispatcher(scope, playwright.firefox),
  41. webkit: new _browserTypeDispatcher.BrowserTypeDispatcher(scope, playwright.webkit),
  42. android,
  43. electron: new _electronDispatcher.ElectronDispatcher(scope, playwright.electron),
  44. utils: playwright.options.isServer ? undefined : new _localUtilsDispatcher.LocalUtilsDispatcher(scope, playwright),
  45. selectors: new _selectorsDispatcher.SelectorsDispatcher(scope, (browserDispatcher === null || browserDispatcher === void 0 ? void 0 : browserDispatcher.selectors) || playwright.selectors),
  46. preLaunchedBrowser: browserDispatcher,
  47. preConnectedAndroidDevice: prelaunchedAndroidDeviceDispatcher,
  48. socksSupport: socksProxy ? new SocksSupportDispatcher(scope, socksProxy) : undefined
  49. });
  50. this._type_Playwright = void 0;
  51. this._browserDispatcher = void 0;
  52. this._type_Playwright = true;
  53. this._browserDispatcher = browserDispatcher;
  54. }
  55. async newRequest(params) {
  56. const request = new _fetch.GlobalAPIRequestContext(this._object, params);
  57. return {
  58. request: _networkDispatchers.APIRequestContextDispatcher.from(this.parentScope(), request)
  59. };
  60. }
  61. async cleanup() {
  62. var _this$_browserDispatc;
  63. // Cleanup contexts upon disconnect.
  64. await ((_this$_browserDispatc = this._browserDispatcher) === null || _this$_browserDispatc === void 0 ? void 0 : _this$_browserDispatc.cleanupContexts());
  65. }
  66. }
  67. exports.PlaywrightDispatcher = PlaywrightDispatcher;
  68. class SocksSupportDispatcher extends _dispatcher.Dispatcher {
  69. constructor(scope, socksProxy) {
  70. super(scope, {
  71. guid: 'socksSupport@' + (0, _utils.createGuid)()
  72. }, 'SocksSupport', {});
  73. this._type_SocksSupport = void 0;
  74. this._socksProxy = void 0;
  75. this._socksListeners = void 0;
  76. this._type_SocksSupport = true;
  77. this._socksProxy = socksProxy;
  78. this._socksListeners = [_eventsHelper.eventsHelper.addEventListener(socksProxy, _socksProxy.SocksProxy.Events.SocksRequested, payload => this._dispatchEvent('socksRequested', payload)), _eventsHelper.eventsHelper.addEventListener(socksProxy, _socksProxy.SocksProxy.Events.SocksData, payload => this._dispatchEvent('socksData', payload)), _eventsHelper.eventsHelper.addEventListener(socksProxy, _socksProxy.SocksProxy.Events.SocksClosed, payload => this._dispatchEvent('socksClosed', payload))];
  79. }
  80. async socksConnected(params) {
  81. var _this$_socksProxy;
  82. (_this$_socksProxy = this._socksProxy) === null || _this$_socksProxy === void 0 ? void 0 : _this$_socksProxy.socketConnected(params);
  83. }
  84. async socksFailed(params) {
  85. var _this$_socksProxy2;
  86. (_this$_socksProxy2 = this._socksProxy) === null || _this$_socksProxy2 === void 0 ? void 0 : _this$_socksProxy2.socketFailed(params);
  87. }
  88. async socksData(params) {
  89. var _this$_socksProxy3;
  90. (_this$_socksProxy3 = this._socksProxy) === null || _this$_socksProxy3 === void 0 ? void 0 : _this$_socksProxy3.sendSocketData(params);
  91. }
  92. async socksError(params) {
  93. var _this$_socksProxy4;
  94. (_this$_socksProxy4 = this._socksProxy) === null || _this$_socksProxy4 === void 0 ? void 0 : _this$_socksProxy4.sendSocketError(params);
  95. }
  96. async socksEnd(params) {
  97. var _this$_socksProxy5;
  98. (_this$_socksProxy5 = this._socksProxy) === null || _this$_socksProxy5 === void 0 ? void 0 : _this$_socksProxy5.sendSocketEnd(params);
  99. }
  100. _onDispose() {
  101. _eventsHelper.eventsHelper.removeEventListeners(this._socksListeners);
  102. }
  103. }