var l=Object.defineProperty;var w=(o,s)=>{for(var e in s)l(o,e,{get:s[e],enumerable:!0})};var f={};w(f,{PuppeteerConnectionAdapter:()=>r,PuppeteerConnectionHelper:()=>u});import*as i from"./../../third_party/puppeteer/puppeteer.js";var p=class extends Error{code;data;constructor(s,e,n){super(s),this.code=e,this.data=n,this.name="ProtocolError"}},r=class extends i.Connection{#e;#s;constructor(s,e){super("",{close:()=>{}}),this.#e=s,this.#e.observe(this),this.#s=e}_rawSend(s,e,n,a,h){return this.#e.send(e,n,a??this.#s).then(t=>{if("error"in t)throw new p(t.error.message,t.error.code,t.error.data);return t.result})}onEvent(s){let{sessionId:e}=s;if(e===this.#s)s.sessionId=void 0;else if(!e||!this._sessions.has(e))return;super.onMessage(JSON.stringify(s))}onDisconnect(){this.dispose()}dispose(){super.dispose(),this.#e.unobserve(this),this.#e.send("Target.detachFromTarget",{sessionId:this.#s},this.#s)}},u=class{static async connectPuppeteerToConnectionViaTab(s){let{connection:e,targetId:n,sessionId:a,isPageTargetCallback:h}=s,t=new r(e,a),g=i.Browser._create(t,[],!1,void 0,void 0,void 0,void 0,void 0,c=>h(c._getTargetInfo()),!1),[,d]=await Promise.all([t._createSession({targetId:n},!0),g]);return await d.waitForTarget(c=>c.type()==="page"),{page:(await d.pages())[0],browser:d,puppeteerConnection:t}}};export{f as PuppeteerConnection};
//# sourceMappingURL=puppeteer.js.map
