import{EventEmitter}from"./EventEmitter.js";import{ExecutionContext}from"./ExecutionContext.js";import{debugError}from"./helper.js";import{JSHandle}from"./JSHandle.js";export class WebWorker extends EventEmitter{constructor(e,t,n,o){let i;super(),this._client=e,this._url=t,this._executionContextPromise=new Promise((e=>this._executionContextCallback=e)),this._client.once("Runtime.executionContextCreated",(async t=>{i=t=>new JSHandle(n,e,t);const n=new ExecutionContext(e,t.context,null);this._executionContextCallback(n)})),this._client.send("Runtime.enable").catch(debugError),this._client.on("Runtime.consoleAPICalled",(e=>n(e.type,e.args.map(i),e.stackTrace))),this._client.on("Runtime.exceptionThrown",(e=>o(e.exceptionDetails)))}url(){return this._url}async executionContext(){return this._executionContextPromise}async evaluate(e,...t){return(await this._executionContextPromise).evaluate(e,...t)}async evaluateHandle(e,...t){return(await this._executionContextPromise).evaluateHandle(e,...t)}}