"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var connection_exports = {}; __export(connection_exports, { Connection: () => Connection }); module.exports = __toCommonJS(connection_exports); var import_eventEmitter = require("./eventEmitter"); var import_android = require("./android"); var import_artifact = require("./artifact"); var import_browser = require("./browser"); var import_browserContext = require("./browserContext"); var import_browserType = require("./browserType"); var import_cdpSession = require("./cdpSession"); var import_channelOwner = require("./channelOwner"); var import_clientInstrumentation = require("./clientInstrumentation"); var import_dialog = require("./dialog"); var import_electron = require("./electron"); var import_elementHandle = require("./elementHandle"); var import_errors = require("./errors"); var import_fetch = require("./fetch"); var import_frame = require("./frame"); var import_jsHandle = require("./jsHandle"); var import_jsonPipe = require("./jsonPipe"); var import_localUtils = require("./localUtils"); var import_network = require("./network"); var import_page = require("./page"); var import_playwright = require("./playwright"); var import_stream = require("./stream"); var import_tracing = require("./tracing"); var import_worker = require("./worker"); var import_writableStream = require("./writableStream"); var import_validator = require("../protocol/validator"); var import_stackTrace = require("../utils/isomorphic/stackTrace"); class Root extends import_channelOwner.ChannelOwner { constructor(connection) { super(connection, "Root", "", {}); } async initialize() { return import_playwright.Playwright.from((await this._channel.initialize({ sdkLanguage: "javascript" })).playwright); } } class DummyChannelOwner extends import_channelOwner.ChannelOwner { } class Connection extends import_eventEmitter.EventEmitter { constructor(platform, localUtils, instrumentation, headers = []) { super(platform); this._objects = /* @__PURE__ */ new Map(); this.onmessage = (message) => { }; this._lastId = 0; this._callbacks = /* @__PURE__ */ new Map(); this._isRemote = false; this._rawBuffers = false; this._tracingCount = 0; this._instrumentation = instrumentation || (0, import_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, options) { 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")) { this._platform.log("channel", "SEND> " + JSON.stringify(message)); } const location = options.frames?.[0] ? { file: options.frames[0].file, line: options.frames[0].line, column: options.frames[0].column } : void 0; const metadata = { title: options.title, location, internal: options.internal, stepId: options.stepId }; if (this._tracingCount && options.frames && type !== "LocalUtils") this._localUtils?.addStackToTracingNoReply({ callData: { stack: options.frames ?? [], id } }).catch(() => { }); this._platform.zones.empty.run(() => this.onmessage({ ...message, metadata })); return await new Promise((resolve, reject) => this._callbacks.set(id, { resolve, reject, title: options.title, 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"))} `; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Connection });