"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Connection = void 0; var _eventEmitter = require("./eventEmitter"); var _android = require("./android"); var _artifact = require("./artifact"); var _browser = require("./browser"); var _browserContext = require("./browserContext"); var _browserType = require("./browserType"); var _cdpSession = require("./cdpSession"); var _channelOwner = require("./channelOwner"); var _clientInstrumentation = require("./clientInstrumentation"); var _dialog = require("./dialog"); var _electron = require("./electron"); var _elementHandle = require("./elementHandle"); var _errors = require("./errors"); var _fetch = require("./fetch"); var _frame = require("./frame"); var _jsHandle = require("./jsHandle"); var _jsonPipe = require("./jsonPipe"); var _localUtils = require("./localUtils"); var _network = require("./network"); var _page = require("./page"); var _playwright = require("./playwright"); var _selectors = require("./selectors"); var _stream = require("./stream"); var _tracing = require("./tracing"); var _worker = require("./worker"); var _writableStream = require("./writableStream"); var _validator = require("../protocol/validator"); var _stackTrace = require("../utils/isomorphic/stackTrace"); /** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the 'License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class Root extends _channelOwner.ChannelOwner { constructor(connection) { super(connection, 'Root', '', {}); } async initialize() { return _playwright.Playwright.from((await this._channel.initialize({ sdkLanguage: 'javascript' })).playwright); } } class DummyChannelOwner extends _channelOwner.ChannelOwner {} class Connection extends _eventEmitter.EventEmitter { constructor(platform, localUtils, instrumentation, headers = []) { super(platform); this._objects = new Map(); this.onmessage = message => {}; this._lastId = 0; this._callbacks = new Map(); this._rootObject = void 0; this._closedError = void 0; this._isRemote = false; this._localUtils = void 0; this._rawBuffers = false; // Some connections allow resolving in-process dispatchers. this.toImpl = void 0; this._tracingCount = 0; this._instrumentation = void 0; // Used from @playwright/test fixtures -> TODO remove? this.headers = void 0; this._instrumentation = instrumentation || (0, _clientInstrumentation.createInstrumentation)(); this._localUtils = localUtils; this._rootObject = new Root(this); this.headers = headers; } markAsRemote() { this._isRemote = true; } isRemote() { return this._isRemote; } useRawBuffers() { this._rawBuffers = true; } rawBuffers() { return this._rawBuffers; } localUtils() { return this._localUtils; } async initializePlaywright() { return await this._rootObject.initialize(); } getObjectWithKnownName(guid) { return this._objects.get(guid); } setIsTracing(isTracing) { if (isTracing) this._tracingCount++;else this._tracingCount--; } async sendMessageToServer(object, method, params, apiName, frames, stepId) { var _this$_localUtils; if (this._closedError) throw this._closedError; if (object._wasCollected) throw new Error('The object has been collected to prevent unbounded heap growth.'); const guid = object._guid; const type = object._type; const id = ++this._lastId; const message = { id, guid, method, params }; if (this._platform.isLogEnabled('channel')) { // Do not include metadata in debug logs to avoid noise. this._platform.log('channel', 'SEND> ' + JSON.stringify(message)); } const location = frames[0] ? { file: frames[0].file, line: frames[0].line, column: frames[0].column } : undefined; const metadata = { apiName, location, internal: !apiName, stepId }; if (this._tracingCount && frames && type !== 'LocalUtils') (_this$_localUtils = this._localUtils) === null || _this$_localUtils === void 0 || _this$_localUtils.addStackToTracingNoReply({ callData: { stack: frames, id } }).catch(() => {}); // We need to exit zones before calling into the server, otherwise // when we receive events from the server, we would be in an API zone. this._platform.zones.empty.run(() => this.onmessage({ ...message, metadata })); return await new Promise((resolve, reject) => this._callbacks.set(id, { resolve, reject, apiName, type, method })); } _validatorFromWireContext() { return { tChannelImpl: this._tChannelImplFromWire.bind(this), binary: this._rawBuffers ? 'buffer' : 'fromBase64', isUnderTest: () => this._platform.isUnderTest() }; } dispatch(message) { if (this._closedError) return; const { id, guid, method, params, result, error, log } = message; if (id) { if (this._platform.isLogEnabled('channel')) this._platform.log('channel', ' !!l)) return ''; return ` Call log: ${platform.colors.dim(log.join('\n'))} `; }