browser-devtools-mcp 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- import{$ as f,W as a,X as b,Y as c,Z as d,_ as e,aa as g,ba as h,ca as i,da as j,ea as k,fa as l,ga as m,ha as n,ia as o,ja as p,ka as q,la as r,ma as s,na as t,oa as u,pa as v,qa as w,ra as x,sa as y,ta as z,ua as A,va as B,wa as C,xa as D,ya as E}from"./core-IV5QBQ2N.js";export{b as DEFAULT_NODE_DEBUG_CONFIG,a as ProbeKind,w as addWatchExpression,p as clearProbes,s as clearSnapshots,t as clearSnapshotsByProbe,z as clearWatchExpressions,m as createProbe,f as detachDebugging,e as disableDebugging,d as enableDebugging,E as evaluateInNode,v as getConsoleMessages,l as getExceptionBreakpoint,C as getOriginalSources,D as getScripts,u as getSnapshotStats,q as getSnapshots,r as getSnapshotsByProbe,h as getStore,c as getStoreKey,B as hasSourceMaps,g as isDebuggingEnabled,o as listProbes,j as listStoreKeys,y as listWatchExpressions,A as loadSourceMaps,n as removeProbe,x as removeWatchExpression,i as resolveSourceLocation,k as setExceptionBreakpoint};
@@ -1,13 +0,0 @@
1
- var ne=Object.defineProperty;var u=(r,e)=>ne(r,"name",{value:e,configurable:!0});import re from"node:path";function h(r){let e=process.env[r];if(!e)return;let t=e.trim();return t||void 0}u(h,"_envStr");function x(r){let e=h(r);if(!e)return;let t=Number(e);if(Number.isFinite(t))return Math.floor(t)}u(x,"_envInt");function _(r){let e=h(r);if(e)return e==="true"}u(_,"_envBool");function se(r){let e={};if(!r)return e;let t=r.split(",");for(let n of t){let s=n.trim();if(!s)continue;let i=s.indexOf("=");if(i===-1)continue;let c=s.slice(0,i).trim(),o=s.slice(i+1).trim();!c||!o||(e[c]=o)}return e}u(se,"_parseKeyValueFromEnv");var Ne=x("PORT")??3e3,F=h("PLATFORM"),we=F==="browser"||F==="node"?F:"browser",De=x("SESSION_IDLE_SECONDS")??300,Ce=x("SESSION_IDLE_CHECK_SECONDS")??30,Ae=_("SESSION_CLOSE_ON_SOCKET_CLOSE")??!1,Te=_("BROWSER_HEADLESS_ENABLE")??!0,Me=_("BROWSER_PERSISTENT_ENABLE")??!1,Le=h("BROWSER_PERSISTENT_USER_DATA_DIR")??re.join(process.cwd(),"browser-devtools-mcp"),ke=_("BROWSER_USE_INSTALLED_ON_SYSTEM")??!1,Be=h("BROWSER_EXECUTABLE_PATH"),Fe=h("BROWSER_LOCALE"),Ve=x("BROWSER_CONSOLE_MESSAGES_BUFFER_SIZE")??1e3,We=x("BROWSER_HTTP_REQUESTS_BUFFER_SIZE")??1e3,V=x("NODE_CONSOLE_MESSAGES_BUFFER_SIZE")??1e3,Ue=_("OTEL_ENABLE")??!1,$e=h("OTEL_SERVICE_NAME")??"frontend",Ge=h("OTEL_SERVICE_VERSION"),ze=h("OTEL_ASSETS_DIR"),He=h("OTEL_INSTRUMENTATION_USER_INTERACTION_EVENTS")?.split(",")??["click"],Ke=h("OTEL_EXPORTER_TYPE")??"none",qe=h("OTEL_EXPORTER_HTTP_URL"),Ze=se(h("OTEL_EXPORTER_HTTP_HEADERS")),Xe=h("AWS_REGION"),je=h("AWS_PROFILE"),Je=_("AMAZON_BEDROCK_ENABLE")??!1,Ye=h("AMAZON_BEDROCK_IMAGE_EMBED_MODEL_ID"),Qe=h("AMAZON_BEDROCK_TEXT_EMBED_MODEL_ID"),et=h("AMAZON_BEDROCK_VISION_MODEL_ID"),tt=h("FIGMA_ACCESS_TOKEN")??"",nt=h("FIGMA_API_BASE_URL")??"https://api.figma.com/v1",rt=x("DAEMON_PORT")??2020,st=x("DAEMON_SESSION_IDLE_SECONDS")??300,it=x("DAEMON_SESSION_IDLE_CHECK_SECONDS")??30;var K=(i=>(i.ALL="all",i.DEBUG="debug",i.INFO="info",i.WARNING="warning",i.ERROR="error",i))(K||{});var q={all:{code:-1},debug:{code:0},info:{code:1},warning:{code:2},error:{code:3}},ie=(o=>(o.GET="GET",o.POST="POST",o.PUT="PUT",o.PATCH="PATCH",o.DELETE="DELETE",o.HEAD="HEAD",o.OPTIONS="OPTIONS",o))(ie||{}),oe=(d=>(d.DOCUMENT="document",d.STYLESHEET="stylesheet",d.IMAGE="image",d.MEDIA="media",d.FONT="font",d.SCRIPT="script",d.TEXTTRACK="texttrack",d.XHR="xhr",d.FETCH="fetch",d.EVENTSOURCE="eventsource",d.WEBSOCKET="websocket",d.MANIFEST="manifest",d.OTHER="other",d))(oe||{});var A="[BROWSER-DEVTOOLS]",O=!0,ae=process.env.DEBUG_ENABLE==="true";function T(){return`${new Date().toLocaleTimeString(void 0,{hour:"numeric",minute:"numeric",second:"numeric",hour12:!1,timeZoneName:"short"})}`}u(T,"_timeAsString");function M(...r){return Z()?r:(r||[]).map(e=>e?e instanceof Error||e.name&&e.message&&e.stack?`${e.name}: ${e.message}`:e:"")}u(M,"_normalizeArgs");function ut(){O=!0}u(ut,"enable");function lt(){O=!1}u(lt,"disable");function Z(){return ae}u(Z,"isDebugEnabled");function N(...r){O&&Z()&&console.debug(A,T(),"|","DEBUG","-",...M(...r))}u(N,"debug");function pt(...r){O&&console.info(A,T(),"|","INFO ","-",...M(...r))}u(pt,"info");function dt(...r){O&&console.warn(A,T(),"|","WARN ","-",...M(...r))}u(dt,"warn");function mt(...r){O&&console.error(A,T(),"|","ERROR","-",...M(...r))}u(mt,"error");function ce(){let r=new WeakSet;return(e,t)=>{if(typeof t=="object"&&t!==null){if(r.has(t))return;r.add(t)}return t}}u(ce,"_getCircularReplacer");function gt(r){return JSON.stringify(r,ce())}u(gt,"toJson");var X="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",j=new Map;for(let r=0;r<X.length;r++)j.set(X[r],r);function le(r){let e=[],t=0,n=0;for(let s of r){let i=j.get(s);if(i===void 0)throw new Error(`Invalid base64 character: ${s}`);let c=(i&32)!==0;if(n+=(i&31)<<t,c)t+=5;else{let o=(n&1)!==0;n=n>>1,o&&(n=-n),e.push(n),n=0,t=0}}return e}u(le,"_decodeVLQ");function pe(r,e){let t=[],n=r.split(";"),s=0,i=0,c=0,o=0,p=0;for(let a of n){let l=0,b=a.split(",");for(let g of b){if(!g)continue;let d=le(g);if(d.length===0)continue;l+=d[0];let S={generatedLine:s,generatedColumn:l};d.length>=4&&(i+=d[1],c+=d[2],o+=d[3],S.source=e[i],S.originalLine=c,S.originalColumn=o,d.length>=5&&(p+=d[4])),t.push(S)}s++}return t}u(pe,"_parseMappings");var L=class{static{u(this,"SourceMapResolver")}scripts=new Map;scriptsByUrl=new Map;sourceToScripts=new Map;fetchCache=new Map;page;customFetcher;constructor(e){typeof e=="function"?this.customFetcher=e:this.page=e}registerScript(e){let t={scriptId:e.scriptId,url:e.url,sourceMapURL:e.sourceMapURL,originalSources:[]};if(this.scripts.set(e.scriptId,t),e.url){let n=this.scriptsByUrl.get(e.url)||[];n.push(t),this.scriptsByUrl.set(e.url,n)}}async loadSourceMap(e){let t=this.scripts.get(e);if(!t||!t.sourceMapURL)return!1;if(t.sourceMap)return!0;try{let n=await this._fetchSourceMap(t.sourceMapURL,t.url);if(!n)return!1;t.sourceMap=n,t.mappings=pe(n.mappings,n.sources),t.originalSources=n.sources.map(s=>this._resolveSourcePath(s,n.sourceRoot,t.url));for(let s of t.originalSources){let i=this.sourceToScripts.get(s)||[];i.push(t),this.sourceToScripts.set(s,i)}return!0}catch(n){return N(`Failed to load source map for ${t.url}:`,n),!1}}async loadAllSourceMaps(){let e=0;for(let t of this.scripts.keys())await this.loadSourceMap(t)&&e++;return e}originalToGenerated(e,t,n=0){let s=this._normalizeSourcePath(e),i=this._findScriptsForSource(s);if(i.length!==0)for(let c of i){if(!c.mappings)continue;let o=c.originalSources.findIndex(l=>this._normalizeSourcePath(l)===s||l.endsWith(s)||s.endsWith(l));if(o===-1)continue;let p,a=1/0;for(let l of c.mappings)if(l.source===c.sourceMap?.sources[o]&&l.originalLine!==void 0&&l.originalLine===t){let b=l.originalColumn!==void 0?Math.abs(l.originalColumn-n):0;b<a&&(a=b,p=l)}if(p)return{scriptId:c.scriptId,location:{line:p.generatedLine,column:p.generatedColumn}}}}async resolveLocationByUrl(e,t,n=1){let s=Math.max(0,t-1),i=Math.max(0,n-1),c=this.scriptsByUrl.get(e)||[];if(c.length===0)for(let o of this.scripts.values())(o.url===e||o.url.endsWith(e)||e.endsWith(o.url))&&c.push(o);for(let o of c){if(!await this.loadSourceMap(o.scriptId)||!o.mappings)continue;let a=this.generatedToOriginal(o.scriptId,s,i);if(a)return a}return null}generatedToOriginal(e,t,n=0){let s=this.scripts.get(e);if(!s?.mappings)return;let i,c=1/0;for(let o of s.mappings){if(o.generatedLine!==t||o.source===void 0)continue;let p=Math.abs(o.generatedColumn-n);p<c&&(c=p,i=o)}if(i&&i.source!==void 0&&i.originalLine!==void 0){let o=s.sourceMap?.sources.indexOf(i.source);return{source:o!==void 0&&o>=0?s.originalSources[o]:i.source,line:i.originalLine,column:i.originalColumn??0,name:i.name}}}getOriginalSources(){return Array.from(this.sourceToScripts.keys())}findScriptsForSource(e){let t=this._normalizeSourcePath(e);return this._findScriptsForSource(t)}hasSourceMaps(){for(let e of this.scripts.values())if(e.sourceMap)return!0;return!1}clear(){this.scripts.clear(),this.scriptsByUrl.clear(),this.sourceToScripts.clear(),this.fetchCache.clear()}_findScriptsForSource(e){let t=this.sourceToScripts.get(e);if(t&&t.length>0)return t;let n=[];for(let[s,i]of this.sourceToScripts.entries()){let c=this._normalizeSourcePath(s);(c.endsWith(e)||e.endsWith(c))&&n.push(...i)}return n}_normalizeSourcePath(e){let t=e.replace(/^webpack:\/\/[^/]*\//,"").replace(/^file:\/\//,"").replace(/^\.*\//,"");for(t=t.replace(/\\/g,"/");t.startsWith("./");)t=t.slice(2);return t}_resolveSourcePath(e,t,n){return e.startsWith("webpack://")||e.startsWith("http://")||e.startsWith("https://")||t&&(e=t.replace(/\/$/,"")+"/"+e),e}async _fetchSourceMap(e,t){if(e.startsWith("data:"))return this._parseDataUrl(e);let n=this._resolveUrl(e,t);if(this.fetchCache.has(n))return this.fetchCache.get(n)||null;try{let s=null;if(this.customFetcher){let i=await this.customFetcher(n,t);i&&(s=JSON.parse(i))}else this.page&&(s=await this._fetchViaBrowser(n));return this.fetchCache.set(n,s),s}catch(s){return N(`Failed to fetch source map from ${n}:`,s),this.fetchCache.set(n,null),null}}_parseDataUrl(e){try{let t=e.match(/^data:[^,]*(?:;base64)?,(.*)$/);if(!t)return null;let n=e.includes(";base64,"),s=t[1],i=n?Buffer.from(s,"base64").toString("utf-8"):decodeURIComponent(s);return JSON.parse(i)}catch{return null}}_resolveUrl(e,t){if(e.startsWith("http://")||e.startsWith("https://"))return e;try{return new URL(e,t).href}catch{return t.replace(/[^/]*$/,"")+e}}async _fetchViaBrowser(e){if(!this.page)return null;try{let t=await this.page.evaluate(async n=>{try{let s=await fetch(n);return s.ok?{data:await s.text()}:{error:`HTTP ${s.status}`}}catch(s){return{error:s.message||"Fetch failed"}}},e);return"error"in t?(N(`Browser fetch error for ${e}: ${t.error}`),null):JSON.parse(t.data)}catch(t){return N(`Failed to fetch ${e} via browser:`,t),null}}};var de={maxDepth:3,maxProperties:50,maxArrayLength:100,maxStringLength:1e3},k=class{static{u(this,"V8Api")}cdp=null;enabled=!1;scripts=new Map;scriptsByUrl=new Map;eventHandlers={};options;cdpProvider;constructor(e,t){if(this.options={...de,...t},typeof e=="function")this.cdpProvider=e;else if(e&&typeof e.context=="function"){let n=e;this.cdpProvider=async()=>await n.context().newCDPSession(n)}else if(e&&typeof e.send=="function"){let n=e;this.cdp=n,this.cdpProvider=async()=>n}else throw new Error("V8Api: Invalid source. Expected Page, CDPSessionProvider, or ICDPSession.")}getOptions(){return{...this.options}}isEnabled(){return this.enabled}async getCdp(){return this.cdp||(this.cdp=await this.cdpProvider()),this.cdp}on(e,t){this.eventHandlers[e]=t}off(e){delete this.eventHandlers[e]}async enable(){if(this.enabled)return;let e=await this.getCdp();e.on("Debugger.scriptParsed",t=>{let n=t;if(this.scripts.set(n.scriptId,n),n.url){let s=this.scriptsByUrl.get(n.url)||[];s.push(n),this.scriptsByUrl.set(n.url,s)}this.eventHandlers.scriptParsed&&this.eventHandlers.scriptParsed(n)}),e.on("Debugger.paused",t=>{let n=t;this.eventHandlers.paused&&this.eventHandlers.paused(n)}),e.on("Debugger.resumed",()=>{this.eventHandlers.resumed&&this.eventHandlers.resumed()}),await e.send("Debugger.enable",{maxScriptsCacheSize:1e8}),await e.send("Runtime.enable"),this.enabled=!0}async disable(){if(!(!this.enabled||!this.cdp)){try{await this.cdp.send("Debugger.disable"),await this.cdp.send("Runtime.disable")}catch{}this.scripts.clear(),this.scriptsByUrl.clear(),this.enabled=!1}}async detach(){if(await this.disable(),this.cdp){try{await this.cdp.detach()}catch{}this.cdp=null}}getScripts(){return Array.from(this.scripts.values())}getScript(e){return this.scripts.get(e)}findScriptsByUrl(e){let t=new RegExp(e),n=[];for(let s of this.scripts.values())s.url&&t.test(s.url)&&n.push(s);return n}async setBreakpointByUrl(e){let t=await this.getCdp(),n={lineNumber:e.lineNumber};e.urlRegex?n.urlRegex=e.urlRegex:e.url&&(n.url=e.url),e.columnNumber!==void 0&&(n.columnNumber=e.columnNumber),e.condition&&(n.condition=e.condition);let s=await t.send("Debugger.setBreakpointByUrl",n);return{breakpointId:s.breakpointId,locations:s.locations||[]}}async setBreakpoint(e,t){let n=await this.getCdp(),s={location:{scriptId:e.scriptId,lineNumber:e.lineNumber,columnNumber:e.columnNumber}};t&&(s.condition=t);let i=await n.send("Debugger.setBreakpoint",s);return{breakpointId:i.breakpointId,actualLocation:i.actualLocation}}async removeBreakpoint(e){await(await this.getCdp()).send("Debugger.removeBreakpoint",{breakpointId:e})}async resume(){await(await this.getCdp()).send("Debugger.resume")}async stepOver(){await(await this.getCdp()).send("Debugger.stepOver")}async stepInto(){await(await this.getCdp()).send("Debugger.stepInto")}async stepOut(){await(await this.getCdp()).send("Debugger.stepOut")}async pause(){await(await this.getCdp()).send("Debugger.pause")}async setPauseOnExceptions(e){await(await this.getCdp()).send("Debugger.setPauseOnExceptions",{state:e})}async evaluateOnCallFrame(e,t,n){let i=await(await this.getCdp()).send("Debugger.evaluateOnCallFrame",{callFrameId:e,expression:t,returnByValue:n?.returnByValue??!0,generatePreview:n?.generatePreview??!0,throwOnSideEffect:n?.throwOnSideEffect??!1});return{result:i.result,exceptionDetails:i.exceptionDetails}}async getProperties(e,t){let s=await(await this.getCdp()).send("Runtime.getProperties",{objectId:e,ownProperties:t?.ownProperties??!0,accessorPropertiesOnly:t?.accessorPropertiesOnly??!1,generatePreview:t?.generatePreview??!0});return{result:s.result||[],internalProperties:s.internalProperties,privateProperties:s.privateProperties}}async getScopeVariables(e,t){if(!e.object.objectId)return{};let n={maxDepth:t?.maxDepth??this.options.maxDepth,maxProperties:t?.maxProperties??this.options.maxProperties,maxArrayLength:t?.maxArrayLength??this.options.maxArrayLength},{result:s}=await this.getProperties(e.object.objectId,{ownProperties:!0,generatePreview:!0}),i={},c=new Set,o=0;for(let p of s){if(o>=n.maxProperties){i.__truncated__=`${s.length-o} more properties`;break}p.value&&(i[p.name]=await this.extractValueDeep(p.value,n.maxDepth,n.maxProperties,n.maxArrayLength,c),o++)}return i}extractValue(e){return this._extractValueShallow(e)}async extractValueDeep(e,t,n,s,i=new Set){let c=t??this.options.maxDepth,o=n??this.options.maxProperties,p=s??this.options.maxArrayLength;if(e.value!==void 0)return typeof e.value=="string"&&e.value.length>this.options.maxStringLength?e.value.slice(0,this.options.maxStringLength)+`... (${e.value.length} chars)`:e.value;if(e.unserializableValue)return e.unserializableValue==="NaN"?NaN:e.unserializableValue==="Infinity"?1/0:e.unserializableValue==="-Infinity"?-1/0:e.unserializableValue==="-0"?-0:e.unserializableValue.endsWith("n")?`BigInt(${e.unserializableValue.slice(0,-1)})`:e.unserializableValue;if(e.subtype==="null")return null;if(e.type!=="undefined"){if(e.type==="function")return`[function${e.description?`: ${e.description.split(`
2
- `)[0]}`:""}]`;if(!e.objectId)return this._extractValueShallow(e);if(c<=0)return this._getShallowDescription(e);if(i.has(e.objectId))return"[Circular]";i.add(e.objectId);try{return e.subtype==="array"?await this._extractArray(e.objectId,c-1,o,p,i):e.subtype==="map"?await this._extractMap(e.objectId,c-1,o,p,i):e.subtype==="set"?await this._extractSet(e.objectId,c-1,p,i):e.subtype==="date"?e.description||"[Date]":e.subtype==="regexp"?e.description||"[RegExp]":e.subtype==="error"?e.description||"[Error]":e.subtype==="promise"?`[Promise: ${e.description||"pending"}]`:e.subtype==="node"||e.className?.includes("Element")||e.className?.includes("Node")?`[DOM: ${e.description||e.className||"Node"}]`:e.type==="object"?await this._extractObject(e.objectId,c-1,o,p,i,e.className):this._extractValueShallow(e)}catch{return this._getShallowDescription(e)}}}async _extractArray(e,t,n,s,i){let{result:c}=await this.getProperties(e,{ownProperties:!0,generatePreview:!0}),o=[],p=0;for(let a of c)if(a.name==="length"&&a.value?.value!==void 0){p=a.value.value;break}for(let a of c){let l=parseInt(a.name,10);if(!(isNaN(l)||l<0)){if(o.length>=s)break;a.value&&(o[l]=await this.extractValueDeep(a.value,t,n,s,i))}}return p>s&&(o.__truncated__=`${p-s} more items`),o}async _extractMap(e,t,n,s,i){let{internalProperties:c}=await this.getProperties(e,{ownProperties:!0,generatePreview:!0}),o={__type__:"Map"},p=[],a=c?.find(l=>l.name==="[[Entries]]");if(a?.value?.objectId){let{result:l}=await this.getProperties(a.value.objectId,{ownProperties:!0,generatePreview:!0}),b=0;for(let g of l){if(b>=s)break;let d=parseInt(g.name,10);if(isNaN(d)||!g.value?.objectId)continue;let{result:S}=await this.getProperties(g.value.objectId,{ownProperties:!0,generatePreview:!0}),v=S.find(E=>E.name==="key"),P=S.find(E=>E.name==="value");if(v?.value&&P?.value){let E=await this.extractValueDeep(v.value,t,n,s,i),f=await this.extractValueDeep(P.value,t,n,s,i);p.push([E,f])}b++}}return o.entries=p,o}async _extractSet(e,t,n,s){let{internalProperties:i}=await this.getProperties(e,{ownProperties:!0,generatePreview:!0}),c={__type__:"Set"},o=[],p=i?.find(a=>a.name==="[[Entries]]");if(p?.value?.objectId){let{result:a}=await this.getProperties(p.value.objectId,{ownProperties:!0,generatePreview:!0}),l=0;for(let b of a){if(l>=n)break;let g=parseInt(b.name,10);isNaN(g)||(b.value&&o.push(await this.extractValueDeep(b.value,t,50,n,s)),l++)}}return c.values=o,c}async _extractObject(e,t,n,s,i,c){let{result:o}=await this.getProperties(e,{ownProperties:!0,generatePreview:!0}),p={};c&&c!=="Object"&&(p.__class__=c);let a=0;for(let l of o){if(a>=n){p.__truncated__=`${o.length-a} more properties`;break}l.isOwn&&(l.name.startsWith("__")&&l.name.endsWith("__")||l.value&&(p[l.name]=await this.extractValueDeep(l.value,t,n,s,i),a++))}return p}_extractValueShallow(e){if(e.value!==void 0)return e.value;if(e.unserializableValue)return e.unserializableValue==="NaN"?NaN:e.unserializableValue==="Infinity"?1/0:e.unserializableValue==="-Infinity"?-1/0:e.unserializableValue==="-0"?-0:e.unserializableValue.endsWith("n")?`BigInt(${e.unserializableValue.slice(0,-1)})`:e.unserializableValue;if(e.subtype==="null")return null;if(e.type!=="undefined")return this._getShallowDescription(e)}_getShallowDescription(e){if(e.description){let t=e.description.split(`
3
- `)[0];return t.length>100?`[${e.type}${e.subtype?`:${e.subtype}`:""}] ${t.slice(0,100)}...`:`[${e.type}${e.subtype?`:${e.subtype}`:""}] ${t}`}return`[${e.type}${e.subtype?`:${e.subtype}`:""}]`}async getScriptSource(e){return await(await this.getCdp()).send("Debugger.getScriptSource",{scriptId:e})}async setScriptSource(e,t,n){let i=await(await this.getCdp()).send("Debugger.setScriptSource",{scriptId:e,scriptSource:t,dryRun:n??!1});return{callFrames:i.callFrames,stackChanged:i.stackChanged,asyncStackTrace:i.asyncStackTrace,exceptionDetails:i.exceptionDetails}}};import*as J from"node:fs";import*as me from"node:http";import*as ge from"node:https";import*as R from"node:path";var fe=(t=>(t.TRACEPOINT="tracepoint",t.LOGPOINT="logpoint",t))(fe||{}),W={maxSnapshots:1e3,maxCallStackDepth:20,maxFramesWithScopes:5,maxAsyncStackSegments:10,maxFramesPerAsyncSegment:10},m=new Map;function U(){let r=Date.now(),e=Math.floor(Math.random()*1e6);return`${r.toString(36)}-${e.toString(36)}`}u(U,"_generateId");function be(r){switch(r){case"error":return"error";case"warning":case"warn":return"warning";case"info":return"info";case"debug":return"debug";default:return"info"}}u(be,"_cdpConsoleTypeToLevelName");function Se(r){return!r||r.length===0?"":r.map(e=>e.type==="string"&&e.value!==void 0||e.value!==void 0?String(e.value):e.description?e.description:"[object]").join(" ")}u(Se,"_cdpArgsToText");function he(r,e){try{let t=r.trim();return/^[=<>!%]/.test(t)&&(t=`hitCount ${t}`),!!new Function("hitCount",`return (${t});`)(e)}catch{return!1}}u(he,"_evaluateHitCondition");async function Ee(r){let e=`(function(){
4
- try {
5
- var api = require('@opentelemetry/api');
6
- var span = api.trace.getActiveSpan();
7
- if (!span) return null;
8
- var ctx = span.spanContext();
9
- return ctx.traceId && ctx.spanId ? { traceId: ctx.traceId, spanId: ctx.spanId } : null;
10
- } catch (e) {
11
- return null;
12
- }
13
- })()`;try{let t=await r.send("Runtime.evaluate",{expression:e,returnByValue:!0,timeout:500});if(t.exceptionDetails)return null;let n=t.result?.value;if(n&&typeof n.traceId=="string"&&typeof n.spanId=="string")return{traceId:n.traceId,spanId:n.spanId}}catch{}return null}u(Ee,"_getOtelTraceContext");function ye(){return async(r,e)=>{let t=null;if(r.startsWith("file://"))t=r.replace("file://","");else if(r.startsWith("/")||r.match(/^[a-zA-Z]:\\/))t=r;else if(e.startsWith("file://")){let n=R.dirname(e.replace("file://",""));t=R.resolve(n,r)}else if(!r.startsWith("http://")&&!r.startsWith("https://")){let n=R.dirname(e.replace(/^file:\/\//,""));t=R.resolve(n,r)}if(t)try{return J.readFileSync(t,"utf-8")}catch{}return r.startsWith("http://")||r.startsWith("https://")?new Promise(n=>{let i=(r.startsWith("https://")?ge:me).get(r,c=>{if(c.statusCode!==200){n(null);return}let o="";c.on("data",p=>{o+=p}),c.on("end",()=>n(o))});i.on("error",()=>n(null)),i.setTimeout(5e3,()=>{i.destroy(),n(null)})}):null}}u(ye,"_createNodeSourceMapFetcher");async function xe(r,e,t=3){let n=[];for(let s of e.scopeChain)if(!(s.type==="global"||s.type==="script"||s.type==="with"||s.type==="eval"||s.type==="wasm-expression-stack")){if(n.length>=t)break;try{let i=await r.getScopeVariables(s),c=[];for(let[o,p]of Object.entries(i))c.push({name:o,value:p,type:typeof p});n.push({type:s.type,name:s.name,variables:c})}catch{}}return n}u(xe,"_captureScopes");async function ve(r,e,t,n){let s=[];t&&(s=await xe(r,e));let i;if(n){let c=n.generatedToOriginal(e.location.scriptId,e.location.lineNumber,e.location.columnNumber??0);c&&(i={source:c.source,line:c.line+1,column:c.column!==void 0?c.column+1:void 0,name:c.name})}return{functionName:e.functionName||"(anonymous)",url:e.url||"",lineNumber:e.location.lineNumber+1,columnNumber:e.location.columnNumber!==void 0?e.location.columnNumber+1:void 0,scriptId:e.location.scriptId,scopes:s,originalLocation:i}}u(ve,"_callFrameToSnapshot");function Pe(r,e,t,n){if(!r)return;let s=t??W.maxAsyncStackSegments,i=n??W.maxFramesPerAsyncSegment,c=[],o=r,p=0;for(;o&&p<s;){let a=[];for(let l of o.callFrames.slice(0,i)){let b;if(e){let g=e.generatedToOriginal(l.location.scriptId,l.location.lineNumber,l.location.columnNumber??0);g&&(b={source:g.source,line:g.line+1,column:g.column!==void 0?g.column+1:void 0,name:g.name})}a.push({functionName:l.functionName||"(anonymous)",url:l.url||"",lineNumber:l.location.lineNumber+1,columnNumber:l.location.columnNumber!==void 0?l.location.columnNumber+1:void 0,originalLocation:b})}a.length>0&&c.push({description:o.description,callFrames:a}),o=o.parent,p++}return c.length===0?void 0:{segments:c}}u(Pe,"_convertAsyncStackTrace");async function Ie(r,e,t){let n={};for(let s of t.values())try{let i=await r.evaluateOnCallFrame(e,s.expression);i.exceptionDetails?n[s.expression]=`[Error: ${i.exceptionDetails.text||"Evaluation failed"}]`:n[s.expression]=await r.extractValueDeep(i.result,2)}catch(i){n[s.expression]=`[Error: ${i.message||"Unknown error"}]`}return n}u(Ie,"_evaluateWatchExpressionsOnFrame");function Lt(r,e){return e||`pid:${r}`}u(Lt,"getStoreKey");async function kt(r,e,t,n,s){if(m.get(r)?.enabled)return;let c=new k(e,n),o=new L(ye()),p={...W,...s},a={v8Api:c,sourceMapResolver:o,probes:new Map,watchExpressions:new Map,snapshots:[],snapshotSequence:0,consoleMessages:[],consoleMessageSequence:0,config:p,enabled:!1,sourceMapsLoaded:!1,exceptionBreakpoint:"none",session:e,processInfo:t};m.set(r,a),await a.v8Api.enable(),e.on("Runtime.consoleAPICalled",l=>{let b=l.type||"log",g=l.args||[],d=Se(g),S=be(b),v=q[S]?.code??1,P,E=l.stackTrace;if(E?.callFrames?.length){let f=E.callFrames[0];P={url:f.url||"",lineNumber:f.lineNumber??0,columnNumber:f.columnNumber??0}}a.consoleMessageSequence++,a.consoleMessages.push({type:b,text:d,level:{name:S,code:v},location:P,timestamp:Date.now(),sequenceNumber:a.consoleMessageSequence}),a.consoleMessages.length>V&&a.consoleMessages.splice(0,a.consoleMessages.length-V)}),a.v8Api.on("scriptParsed",l=>{a.sourceMapResolver.registerScript(l)});for(let l of a.v8Api.getScripts())a.sourceMapResolver.registerScript(l);a.v8Api.on("paused",async l=>{let b=Date.now();try{let g=l.reason==="exception"||l.reason==="promiseRejection",d=l.hitBreakpoints||[],S,v=!0;for(let f of a.probes.values()){if(!f.enabled)continue;if(f.v8BreakpointIds.some(D=>d.includes(D))){S=f,f.hitCondition&&(v=he(f.hitCondition,f.hitCount+1));break}}let P=S!==void 0&&v,E=g&&a.exceptionBreakpoint!=="none";if(S&&(S.hitCount++,S.lastHitAt=Date.now()),(P||E)&&l.callFrames.length>0){let f=l.callFrames[0],w;if(S?.kind==="logpoint"&&S.logExpression)try{let y=await a.v8Api.evaluateOnCallFrame(f.callFrameId,S.logExpression,{returnByValue:!0,generatePreview:!0});w=a.v8Api.extractValue(y.result)}catch{w="[evaluation error]"}let D;if(g&&l.data){let y=l.data;D={type:l.reason==="promiseRejection"?"promiseRejection":"exception",message:y.description||y.value||String(y),name:y.className,stack:y.description}}let $,I=a.sourceMapResolver.generatedToOriginal(f.location.scriptId,f.location.lineNumber,f.location.columnNumber??0);I&&($={source:I.source,line:I.line+1,column:I.column!==void 0?I.column+1:void 0,name:I.name});let Y=S?.id??"__exception__",B=S?.kind==="logpoint",G=[];if(!B){let y=l.callFrames.slice(0,a.config.maxCallStackDepth);for(let C=0;C<y.length;C++){let te=await ve(a.v8Api,y[C],C<a.config.maxFramesWithScopes,a.sourceMapResolver);G.push(te)}}let z;B||(z=Pe(l.asyncStackTrace,a.sourceMapResolver,a.config.maxAsyncStackSegments,a.config.maxFramesPerAsyncSegment));let H;!B&&a.watchExpressions.size>0&&(H=await Ie(a.v8Api,f.callFrameId,a.watchExpressions));let Q=await Ee(a.session),ee={id:U(),probeId:Y,timestamp:Date.now(),sequenceNumber:++a.snapshotSequence,url:f.url||"",lineNumber:f.location.lineNumber+1,columnNumber:f.location.columnNumber!==void 0?f.location.columnNumber+1:void 0,originalLocation:$,exception:D,callStack:G,asyncStackTrace:z,logResult:w,watchResults:H,captureTimeMs:Date.now()-b,traceContext:Q??void 0};a.snapshots.push(ee),a.snapshots.length>a.config.maxSnapshots&&a.snapshots.splice(0,a.snapshots.length-a.config.maxSnapshots)}}finally{await a.v8Api.resume()}}),a.enabled=!0,a.sourceMapResolver.loadAllSourceMaps().then(()=>{a.sourceMapsLoaded=!0}).catch(()=>{})}u(kt,"enableDebugging");async function _e(r){let e=m.get(r);if(e?.enabled){for(let t of e.probes.values())for(let n of t.v8BreakpointIds)try{await e.v8Api.removeBreakpoint(n)}catch{}e.probes.clear(),e.snapshots.length=0,e.snapshotSequence=0,e.consoleMessages.length=0,e.consoleMessageSequence=0,await e.v8Api.disable(),e.enabled=!1}}u(_e,"disableDebugging");async function Bt(r){let e=m.get(r);e&&(await _e(r),await e.v8Api.detach(),m.delete(r))}u(Bt,"detachDebugging");function Ft(r){return m.get(r)?.enabled??!1}u(Ft,"isDebuggingEnabled");function Vt(r){return m.get(r)}u(Vt,"getStore");async function Wt(r,e,t,n=1){let s=m.get(r);if(!s?.enabled)throw new Error("Not connected to Node.js process or debugging not enabled. Call debug_connect first.");let i=await s.sourceMapResolver.resolveLocationByUrl(e,t,n);return i?{source:i.source,line:i.line+1,column:i.column+1,name:i.name}:null}u(Wt,"resolveSourceLocation");function Ut(){return Array.from(m.keys())}u(Ut,"listStoreKeys");async function $t(r,e){let t=m.get(r);if(!t?.enabled)throw new Error("Debugging is not enabled");await t.v8Api.setPauseOnExceptions(e),t.exceptionBreakpoint=e}u($t,"setExceptionBreakpoint");function Gt(r){return m.get(r)?.exceptionBreakpoint??"none"}u(Gt,"getExceptionBreakpoint");async function zt(r,e){let t=m.get(r);if(!t?.enabled)throw new Error("Debugging is not enabled");let n=U(),s=e.condition?`(${e.condition})`:"true",i=e.lineNumber-1,c=(e.columnNumber??1)-1,o=t.sourceMapResolver.originalToGenerated(e.urlPattern,i,c),p,a=0;if(o)p=(await t.v8Api.setBreakpoint({scriptId:o.scriptId,lineNumber:o.location.line,columnNumber:o.location.column},s)).breakpointId,a=1;else{let g=e.urlPattern.replace(/\\([.*+?^${}()|[\]\\/-])/g,"$1").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\\\*/g,".*").replace(/\\\?/g,"."),d=await t.v8Api.setBreakpointByUrl({urlRegex:g,lineNumber:e.lineNumber-1,columnNumber:e.columnNumber?e.columnNumber-1:void 0,condition:s});p=d.breakpointId,a=d.locations.length}let l={id:n,kind:e.kind,enabled:!0,urlPattern:e.urlPattern,lineNumber:e.lineNumber,columnNumber:e.columnNumber,condition:e.condition,logExpression:e.logExpression,hitCondition:e.hitCondition,v8BreakpointIds:[p],resolvedLocations:a,hitCount:0,createdAt:Date.now()};return t.probes.set(n,l),l}u(zt,"createProbe");async function Ht(r,e){let t=m.get(r);if(!t)return!1;let n=t.probes.get(e);if(!n)return!1;for(let s of n.v8BreakpointIds)try{await t.v8Api.removeBreakpoint(s)}catch{}return t.probes.delete(e),!0}u(Ht,"removeProbe");function Kt(r){return Array.from(m.get(r)?.probes.values()??[])}u(Kt,"listProbes");async function qt(r){let e=m.get(r);if(!e)return 0;let t=e.probes.size;for(let n of e.probes.values())for(let s of n.v8BreakpointIds)try{await e.v8Api.removeBreakpoint(s)}catch{}return e.probes.clear(),t}u(qt,"clearProbes");function Zt(r){return[...m.get(r)?.snapshots??[]]}u(Zt,"getSnapshots");function Xt(r,e){return(m.get(r)?.snapshots??[]).filter(t=>t.probeId===e)}u(Xt,"getSnapshotsByProbe");function jt(r){let e=m.get(r);if(!e)return 0;let t=e.snapshots.length;return e.snapshots.length=0,t}u(jt,"clearSnapshots");function Jt(r,e){let t=m.get(r);if(!t)return 0;let n=t.snapshots.length;return t.snapshots=t.snapshots.filter(s=>s.probeId!==e),n-t.snapshots.length}u(Jt,"clearSnapshotsByProbe");function Yt(r){let e=m.get(r);if(!e||e.snapshots.length===0)return{totalSnapshots:0,snapshotsByProbe:{},averageCaptureTimeMs:0};let t={},n=0;for(let s of e.snapshots)t[s.probeId]=(t[s.probeId]||0)+1,n+=s.captureTimeMs;return{totalSnapshots:e.snapshots.length,snapshotsByProbe:t,oldestTimestamp:e.snapshots[0].timestamp,newestTimestamp:e.snapshots[e.snapshots.length-1].timestamp,averageCaptureTimeMs:n/e.snapshots.length}}u(Yt,"getSnapshotStats");function Qt(r){return[...m.get(r)?.consoleMessages??[]]}u(Qt,"getConsoleMessages");function en(r,e){let t=m.get(r);if(!t)throw new Error("Debug store not initialized");let n=U(),s={id:n,expression:e,createdAt:Date.now()};return t.watchExpressions.set(n,s),s}u(en,"addWatchExpression");function tn(r,e){return m.get(r)?.watchExpressions.delete(e)??!1}u(tn,"removeWatchExpression");function nn(r){return Array.from(m.get(r)?.watchExpressions.values()??[])}u(nn,"listWatchExpressions");function rn(r){let e=m.get(r);if(!e)return 0;let t=e.watchExpressions.size;return e.watchExpressions.clear(),t}u(rn,"clearWatchExpressions");async function sn(r){let e=m.get(r);if(!e?.enabled)throw new Error("Debugging is not enabled");let t=await e.sourceMapResolver.loadAllSourceMaps(),n=e.sourceMapResolver.getOriginalSources();return e.sourceMapsLoaded=!0,{loaded:t,sources:n}}u(sn,"loadSourceMaps");function on(r){return m.get(r)?.sourceMapResolver.hasSourceMaps()??!1}u(on,"hasSourceMaps");function an(r){return m.get(r)?.sourceMapResolver.getOriginalSources()??[]}u(an,"getOriginalSources");function cn(r){return m.get(r)?.v8Api.getScripts()??[]}u(cn,"getScripts");async function un(r,e,t=5e3){let n=m.get(r);if(!n?.enabled)throw new Error("Not connected to Node.js process or debugging not enabled. Call debug_connect first.");let s=await n.session.send("Runtime.evaluate",{expression:e,returnByValue:!0,timeout:Math.min(t,3e4)});if(s.exceptionDetails){let i=s.exceptionDetails,c=i.text??i.description??i.exception?.description;throw new Error(`Node evaluation failed: ${c??JSON.stringify(i)}`)}return n.v8Api.extractValue(s.result)}u(un,"evaluateInNode");export{u as a,Ne as b,we as c,De as d,Ce as e,Ae as f,Te as g,Me as h,Le as i,ke as j,Be as k,Fe as l,Ve as m,We as n,V as o,Ue as p,$e as q,Ge as r,ze as s,He as t,Ke as u,qe as v,Ze as w,Xe as x,je as y,Je as z,Ye as A,Qe as B,et as C,tt as D,nt as E,rt as F,st as G,it as H,ut as I,lt as J,Z as K,N as L,pt as M,dt as N,mt as O,gt as P,k as Q,L as R,K as S,q as T,ie as U,oe as V,fe as W,W as X,Lt as Y,kt as Z,_e as _,Bt as $,Ft as aa,Vt as ba,Wt as ca,Ut as da,$t as ea,Gt as fa,zt as ga,Ht as ha,Kt as ia,qt as ja,Zt as ka,Xt as la,jt as ma,Jt as na,Yt as oa,Qt as pa,en as qa,tn as ra,nn as sa,rn as ta,sn as ua,on as va,an as wa,cn as xa,un as ya};