/**
 * @license
 * Copyright 2025 ReverseCraft
 * SPDX-License-Identifier: Apache-2.0
 */
import{PuppeteerDevToolsConnection as e}from"../core/devtools-connection-adapter.js";import{ISSUE_UTILS as t}from"../issue-descriptions.js";import{logger as s}from"./logger.js";import{Mutex as r}from"./mutex.js";import{DevTools as o}from"../third-party/index.js";export function extractUrlLikeFromDevToolsTitle(e){const t=e.match(new RegExp("DevTools - (.*)"));return t?.[1]??void 0}export function urlsEqual(e,t){return n(e)===n(t)}function n(e){let t=e.trim();t.startsWith("https://")?t=t.slice(8):t.startsWith("http://")&&(t=t.slice(7)),t.startsWith("www.")&&(t=t.slice(4));const s=t.lastIndexOf("#");return-1!==s&&(t=t.slice(0,s)),t.endsWith("/")&&(t=t.slice(0,-1)),t}export class FakeIssuesManager extends o.Common.ObjectWrapper.ObjectWrapper{issues(){return[]}}export function mapIssueToMessageObject(e){const r=e.getAggregatedIssuesCount(),n=e.getDescription(),i=n?.file;if(!n)return s("no description found for issue:"+e.code),null;const a=i?t.getIssueDescription(i):null;if(!a)return s(`no markdown ${i} found for issue:`+e.code),null;let u,c;try{u=o.MarkdownIssueDescription.substitutePlaceholders(a,n.substitutions);const e=o.Marked.Marked.lexer(u);c=o.MarkdownIssueDescription.findTitleFromMarkdownAst(e)}catch{return s("error parsing markdown for issue "+e.code()),null}return c?{type:"issue",item:e,message:c,count:r,description:u}:(s("cannot read issue title from "+i),null)}o.ProtocolClient.InspectorBackend.test.suppressRequestErrors=!0,o.I18n.DevToolsLocale.DevToolsLocale.instance({create:!0,data:{navigatorLanguage:"en-US",settingLanguage:"en-US",lookupClosestDevToolsLocale:e=>e}}),o.I18n.i18n.registerLocaleDataForTest("en-US",{});export class UniverseManager{#e;#t;#s=new WeakMap;#r=new r;constructor(e,t=i){this.#e=e,this.#t=t}async init(e){try{await this.#r.acquire();const t=[];for(const s of e)t.push(this.#t(s).then(e=>this.#s.set(s,e)));this.#e.on("targetcreated",this.#o),this.#e.on("targetdestroyed",this.#n),await Promise.all(t)}finally{this.#r.release()}}get(e){return this.#s.get(e)??null}dispose(){this.#e.off("targetcreated",this.#o),this.#e.off("targetdestroyed",this.#n)}#o=async e=>{const t=await e.page();try{if(await this.#r.acquire(),!t||this.#s.has(t))return;this.#s.set(t,await this.#t(t))}finally{this.#r.release()}};#n=async e=>{const t=await e.page();try{if(await this.#r.acquire(),!t||!this.#s.has(t))return;this.#s.delete(t)}finally{this.#r.release()}}}const i=async t=>{const s=new o.Common.Settings.SettingsStorage({}),r=new o.Foundation.Universe.Universe({settingsCreationOptions:{syncedStorage:s,globalStorage:s,localStorage:s,settingRegistrations:o.Common.SettingRegistration.getRegisteredSettings()},overrideAutoStartModels:new Set([o.DebuggerModel])}),n=await t.createCDPSession(),i=new e(n),u=r.context.get(o.TargetManager);u.observeModels(o.DebuggerModel,a);return{target:u.createTarget("main","","frame",null,n.id(),void 0,i),universe:r}},a={modelAdded(e){e.agent.invoke_setSkipAllPauses({skip:!0})},modelRemoved(){}};