@react-native/debugger-frontend
Version:
Debugger frontend for React Native based on Chrome DevTools
1 lines • 58.9 kB
JavaScript
import*as e from"../../ui/legacy/legacy.js";import*as t from"../../core/sdk/sdk.js";import*as n from"../../core/common/common.js";import*as s from"../../core/host/host.js";import*as i from"../../core/i18n/i18n.js";import*as r from"../../core/platform/platform.js";import*as o from"../logs/logs.js";import*as a from"../../ui/legacy/components/utils/utils.js";import*as c from"../../ui/legacy/theme_support/theme_support.js";import*as d from"../bindings/bindings.js";import*as u from"../har/har.js";import*as l from"../text_utils/text_utils.js";import*as h from"../workspace/workspace.js";self.injectedExtensionAPI=function(e,t,n,s,i,r,o){const a=new Set(s),c=window.chrome||{};if(Object.getOwnPropertyDescriptor(c,"devtools"))return;let d=!1,u=!1;function l(e,t){this._type=e,this._listeners=[],this._customDispatch=t}function h(){this.onRequestFinished=new S("network-request-finished",(function(e){const t=e.arguments[1];t.__proto__=new C(e.arguments[0]),this._fire(t)})),x(this,"network","onFinished","onRequestFinished"),this.onNavigated=new S("inspected-url-changed")}function p(e){this._id=e}function g(){const e={elements:new U,sources:new M,network:new k};function t(t){return e[t]}for(const n in e)Object.defineProperty(this,n,{get:t.bind(null,n),enumerable:!0})}function m(e){this._id=e,e&&(this.onShown=new S("view-shown-"+e,(function(e){const t=e.arguments[0];"number"==typeof t?this._fire(window.parent.frames[t]):this._fire()})),this.onHidden=new S("view-hidden,"+e))}function f(e){m.call(this,null),this._hostPanelName=e,this.onSelectionChanged=new S("panel-objectSelected-"+e)}function w(){this._plugins=new Map}function b(){this._plugins=new Map}function R(){}function E(e){return function(...t){const n={__proto__:e.prototype};e.apply(n,t),function(e,t){for(const n in t){if("_"===n.charAt(0))continue;let s=null;for(let e=t;e&&!s;e=e.__proto__)s=Object.getOwnPropertyDescriptor(e,n);s&&("function"==typeof s.value?e[n]=s.value.bind(t):"function"==typeof s.get?e.__defineGetter__(n,s.get.bind(t)):Object.defineProperty(e,n,s))}}(this,n)}}function x(e,t,n,s){let i=!1;e.__defineGetter__(n,(function(){return i||(console.warn(t+"."+n+" is deprecated. Use "+t+"."+s+" instead"),i=!0),e[s]}))}function y(e){const t=e[e.length-1];return"function"==typeof t?t:void 0}l.prototype={addListener:function(e){if("function"!=typeof e)throw new Error("addListener: callback is not a function");0===this._listeners.length&&$.sendRequest({command:"subscribe",type:this._type}),this._listeners.push(e),$.registerHandler("notify-"+this._type,this._dispatch.bind(this))},removeListener:function(e){const t=this._listeners;for(let n=0;n<t.length;++n)if(t[n]===e){t.splice(n,1);break}0===this._listeners.length&&$.sendRequest({command:"unsubscribe",type:this._type})},_fire:function(...e){const t=this._listeners.slice();for(let e=0;e<t.length;++e)t[e].apply(null,Array.from(arguments))},_dispatch:function(e){this._customDispatch?this._customDispatch.call(this,e):this._fire.apply(this,e.arguments)}},h.prototype={getHAR:function(e){$.sendRequest({command:"getHAR"},e&&function(t){const n=t,s=n?.entries||[];for(let e=0;e<s.length;++e)s[e].__proto__=new C(s[e]._requestId),delete s[e]._requestId;e?.(n)})},addRequestHeaders:function(e){$.sendRequest({command:"addRequestHeaders",headers:e,extensionId:window.location.hostname})}},p.prototype={getContent:function(e){$.sendRequest({command:"getRequestContent",id:this._id},e&&function(t){const{content:n,encoding:s}=t;e?.(n,s)})}},g.prototype={create:function(e,t,n,s){const i="extension-panel-"+$.nextObjectId();$.sendRequest({command:"createPanel",id:i,title:e,page:n},s&&(()=>s.call(this,new O(i))))},setOpenResourceHandler:function(e){const t=$.hasHandler("open-resource");e?$.registerHandler("open-resource",(function(t){d=!0;try{const{resource:n,lineNumber:s}=t;e.call(null,new H(n),s)}finally{d=!1}})):$.unregisterHandler("open-resource"),t===!e&&$.sendRequest({command:"setOpenResourceHandler",handlerPresent:Boolean(e)})},setThemeChangeHandler:function(e){const t=$.hasHandler("host-theme-change");e?$.registerHandler("host-theme-change",(function(t){const{themeName:n}=t;c.devtools.panels.themeName=n,e.call(null,n)})):$.unregisterHandler("host-theme-change"),t===!e&&$.sendRequest({command:"setThemeChangeHandler",handlerPresent:Boolean(e)})},openResource:function(e,t,n,s){const i=y(arguments),r="number"==typeof n?n:0;$.sendRequest({command:"openResource",url:e,lineNumber:t,columnNumber:r},i)},get SearchAction(){return{CancelSearch:"cancelSearch",PerformSearch:"performSearch",NextSearchResult:"nextSearchResult",PreviousSearchResult:"previousSearchResult"}}},f.prototype={createSidebarPane:function(e,t){const n="extension-sidebar-"+$.nextObjectId();$.sendRequest({command:"createSidebarPane",panel:this._hostPanelName,id:n,title:e},t&&function(){t?.(new P(n))})},__proto__:m.prototype},w.prototype={registerRecorderExtensionPlugin:async function(e,t,n){if(this._plugins.has(e))throw new Error(`Tried to register plugin '${t}' twice`);const s=new MessageChannel,i=s.port1;this._plugins.set(e,i),i.onmessage=({data:t})=>{const{requestId:n}=t;(async function(t){switch(t.method){case"stringify":return await e.stringify(t.parameters.recording);case"stringifyStep":return await e.stringifyStep(t.parameters.step);case"replay":try{return d=!0,u=!0,e.replay(t.parameters.recording)}finally{d=!1,u=!1}default:throw new Error(`'${t.method}' is not recognized`)}})(t).then((e=>i.postMessage({requestId:n,result:e}))).catch((e=>i.postMessage({requestId:n,error:{message:e.message}})))};const r=[];"stringify"in e&&"stringifyStep"in e&&r.push("export"),"replay"in e&&r.push("replay"),await new Promise((e=>{$.sendRequest({command:"registerRecorderExtensionPlugin",pluginName:t,mediaType:n,capabilities:r,port:s.port2},(()=>e()),[s.port2])}))},unregisterRecorderExtensionPlugin:async function(e){const t=this._plugins.get(e);if(!t)throw new Error("Tried to unregister a plugin that was not previously registered");this._plugins.delete(e),t.postMessage({event:"unregisteredRecorderExtensionPlugin"}),t.close()},createView:async function(e,t){const n="recorder-extension-view-"+$.nextObjectId();return await new Promise((s=>{$.sendRequest({command:"createRecorderView",id:n,title:e,pagePath:t},s)})),new L(n)}},b.prototype={registerLanguageExtensionPlugin:async function(e,t,n){if(this._plugins.has(e))throw new Error(`Tried to register plugin '${t}' twice`);const s=new MessageChannel,i=s.port1;this._plugins.set(e,i),i.onmessage=({data:t})=>{const{requestId:n}=t;console.time(`${n}: ${t.method}`),function(t){switch(t.method){case"addRawModule":return e.addRawModule(t.parameters.rawModuleId,t.parameters.symbolsURL,t.parameters.rawModule);case"removeRawModule":return e.removeRawModule(t.parameters.rawModuleId);case"sourceLocationToRawLocation":return e.sourceLocationToRawLocation(t.parameters.sourceLocation);case"rawLocationToSourceLocation":return e.rawLocationToSourceLocation(t.parameters.rawLocation);case"getScopeInfo":return e.getScopeInfo(t.parameters.type);case"listVariablesInScope":return e.listVariablesInScope(t.parameters.rawLocation);case"getFunctionInfo":return e.getFunctionInfo(t.parameters.rawLocation);case"getInlinedFunctionRanges":return e.getInlinedFunctionRanges(t.parameters.rawLocation);case"getInlinedCalleesRanges":return e.getInlinedCalleesRanges(t.parameters.rawLocation);case"getMappedLines":return"getMappedLines"in e?e.getMappedLines(t.parameters.rawModuleId,t.parameters.sourceFileURL):Promise.resolve(void 0);case"formatValue":return"evaluate"in e&&e.evaluate?e.evaluate(t.parameters.expression,t.parameters.context,t.parameters.stopId):Promise.resolve(void 0);case"getProperties":if("getProperties"in e&&e.getProperties)return e.getProperties(t.parameters.objectId);if(!("evaluate"in e)||!e.evaluate)return Promise.resolve(void 0);break;case"releaseObject":if("releaseObject"in e&&e.releaseObject)return e.releaseObject(t.parameters.objectId)}throw new Error(`Unknown language plugin method ${t.method}`)}(t).then((e=>i.postMessage({requestId:n,result:e}))).catch((e=>i.postMessage({requestId:n,error:{message:e.message}}))).finally((()=>console.timeEnd(`${n}: ${t.method}`)))},await new Promise((e=>{$.sendRequest({command:"registerLanguageExtensionPlugin",pluginName:t,port:s.port2,supportedScriptTypes:n},(()=>e()),[s.port2])}))},unregisterLanguageExtensionPlugin:async function(e){const t=this._plugins.get(e);if(!t)throw new Error("Tried to unregister a plugin that was not previously registered");this._plugins.delete(e),t.postMessage({event:"unregisteredLanguageExtensionPlugin"}),t.close()},getWasmLinearMemory:async function(e,t,n){const s=await new Promise((s=>$.sendRequest({command:"getWasmLinearMemory",offset:e,length:t,stopId:n},s)));return Array.isArray(s)?new Uint8Array(s).buffer:new ArrayBuffer(0)},getWasmLocal:async function(e,t){return await new Promise((n=>$.sendRequest({command:"getWasmLocal",local:e,stopId:t},n)))},getWasmGlobal:async function(e,t){return await new Promise((n=>$.sendRequest({command:"getWasmGlobal",global:e,stopId:t},n)))},getWasmOp:async function(e,t){return await new Promise((n=>$.sendRequest({command:"getWasmOp",op:e,stopId:t},n)))},reportResourceLoad:function(e,t){return new Promise((n=>$.sendRequest({command:"reportResourceLoad",extensionId:window.location.origin,resourceUrl:e,status:t},n)))}},R.prototype={show:function(e){return new Promise((t=>$.sendRequest({command:"showNetworkPanel",filter:e?.filter},(()=>t()))))}};const _=E(b),v=E(w),I=E((function(){this.onProfilingStarted=new S("profiling-started-",(function(){this._fire()})),this.onProfilingStopped=new S("profiling-stopped-",(function(){this._fire()}))})),A=E(F),S=E(l),O=E(q),L=E(D),P=E(N),T=E(f),C=E(p),H=E(W),k=E(R);class U extends T{constructor(){super("elements")}}class M extends T{constructor(){super("sources")}}function q(e){m.call(this,e),this.onSearch=new S("panel-search-"+e)}function D(e){m.call(this,e)}function N(e){m.call(this,e)}function F(e){this._id=e,this.onClicked=new S("button-clicked-"+e)}function j(){this.onResourceAdded=new S("resource-added",(function(e){const t=e.arguments[0];this._fire(new H(t))})),this.onResourceContentCommitted=new S("resource-content-committed",(function(e){const t=e.arguments[0];this._fire(new H(t),e.arguments[1])}))}function W(e){this._url=e.url,this._type=e.type}q.prototype={createStatusBarButton:function(e,t,n){const s="button-"+$.nextObjectId();return $.sendRequest({command:"createToolbarButton",panel:this._id,id:s,icon:e,tooltip:t,disabled:Boolean(n)}),new A(s)},show:function(){d&&$.sendRequest({command:"showPanel",id:this._id})},__proto__:m.prototype},D.prototype={show:function(){d&&u&&$.sendRequest({command:"showRecorderView",id:this._id})},__proto__:m.prototype},N.prototype={setHeight:function(e){$.sendRequest({command:"setSidebarHeight",id:this._id,height:e})},setExpression:function(e,t,n,s){$.sendRequest({command:"setSidebarContent",id:this._id,expression:e,rootTitle:t,evaluateOnPage:!0,evaluateOptions:"object"==typeof n?n:{}},y(arguments))},setObject:function(e,t,n){$.sendRequest({command:"setSidebarContent",id:this._id,expression:e,rootTitle:t},n)},setPage:function(e){$.sendRequest({command:"setSidebarPage",id:this._id,page:e})},__proto__:m.prototype},F.prototype={update:function(e,t,n){$.sendRequest({command:"updateButton",id:this._id,icon:e,tooltip:t,disabled:Boolean(n)})}},j.prototype={reload:function(e){let t=null;"object"==typeof e?t=e:"string"==typeof e&&(t={userAgent:e},console.warn("Passing userAgent as string parameter to inspectedWindow.reload() is deprecated. Use inspectedWindow.reload({ userAgent: value}) instead.")),$.sendRequest({command:"Reload",options:t})},eval:function(e,t){const n=y(arguments);return $.sendRequest({command:"evaluateOnInspectedPage",expression:e,evaluateOptions:"object"==typeof t?t:void 0},n&&function(e){const{isError:t,isException:s,value:i}=e;t||s?n?.(void 0,e):n?.(i)}),null},getResources:function(e){function t(e){return new H(e)}$.sendRequest({command:"getPageResources"},e&&function(n){e?.(n.map(t))})}},W.prototype={get url(){return this._url},get type(){return this._type},getContent:function(e){$.sendRequest({command:"getResourceContent",url:this._url},e&&function(t){const{content:n,encoding:s}=t;e?.(n,s)})},setContent:function(e,t,n){$.sendRequest({command:"setResourceContent",url:this._url,content:e,commit:t},n)},setFunctionRangesForScript:function(e){return new Promise(((t,n)=>$.sendRequest({command:"setFunctionRangesForScript",scriptUrl:this._url,ranges:e},(e=>{const s=e;s.isError?n(s):t()}))))},attachSourceMapURL:function(e){return new Promise(((t,n)=>$.sendRequest({command:"attachSourceMapToResource",contentUrl:this._url,sourceMapURL:e},(e=>{const s=e;s.isError?n(new Error(s.description)):t()}))))}};let B=[],V=null;function G(){V=null,$.sendRequest({command:"_forwardKeyboardEvent",entries:B}),B=[]}function K(e){this._callbacks={},this._handlers={},this._lastRequestId=0,this._lastObjectId=0,this.registerHandler("callback",this._onCallback.bind(this));const t=new MessageChannel;this._port=t.port1,this._port.addEventListener("message",this._onMessage.bind(this),!1),this._port.start(),e.postMessage("registerExtension","*",[t.port2])}document.addEventListener("keydown",(function(e){const t=document.activeElement;if(t){if(("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName||t.isContentEditable)&&!(e.ctrlKey||e.altKey||e.metaKey))return}let n=0;e.shiftKey&&(n|=1),e.ctrlKey&&(n|=2),e.altKey&&(n|=4),e.metaKey&&(n|=8);const s=255&e.keyCode|n<<8;if(!a.has(s))return;e.preventDefault();const i={eventType:e.type,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey,keyIdentifier:e.keyIdentifier,key:e.key,code:e.code,location:e.location,keyCode:e.keyCode};B.push(i),V||(V=window.setTimeout(G,0))}),!1),K.prototype={sendRequest:function(e,t,n){"function"==typeof t&&(e.requestId=this._registerCallback(t)),this._port.postMessage(e,n)},hasHandler:function(e){return Boolean(this._handlers[e])},registerHandler:function(e,t){this._handlers[e]=t},unregisterHandler:function(e){delete this._handlers[e]},nextObjectId:function(){return r.toString()+"_"+ ++this._lastObjectId},_registerCallback:function(e){const t=++this._lastRequestId;return this._callbacks[t]=e,t},_onCallback:function(e){if(e.requestId in this._callbacks){const t=this._callbacks[e.requestId];delete this._callbacks[e.requestId],t(e.result)}},_onMessage:function(e){const t=e.data,n=this._handlers[t.command];n&&n.call(this,t)}};const $=new K(o||window.parent),z=new function(){this.inspectedWindow=new j,this.panels=new g,this.network=new h,this.languageServices=new _,this.recorder=new v,this.performance=new I,x(this,"webInspector","resources","network")};if(Object.defineProperty(c,"devtools",{value:{},enumerable:!0}),c.devtools.inspectedWindow={},Object.defineProperty(c.devtools.inspectedWindow,"tabId",{get:function(){return t}}),c.devtools.inspectedWindow.__proto__=z.inspectedWindow,c.devtools.network=z.network,c.devtools.panels=z.panels,c.devtools.panels.themeName=n,c.devtools.languageServices=z.languageServices,c.devtools.recorder=z.recorder,c.devtools.performance=z.performance,!1!==e.exposeExperimentalAPIs){c.experimental=c.experimental||{},c.experimental.devtools=c.experimental.devtools||{};const e=Object.getOwnPropertyNames(z);for(let t=0;t<e.length;++t){const n=Object.getOwnPropertyDescriptor(z,e[t]);n&&Object.defineProperty(c.experimental.devtools,e[t],n)}c.experimental.devtools.inspectedWindow=c.devtools.inspectedWindow}e.exposeWebInspectorNamespace&&(window.webInspector=z),i($,z)},self.buildExtensionAPIInjectedScript=function(e,t,n,s,i){const r=[e,t||null,n,s].map((e=>JSON.stringify(e))).join(",");return i||(i=()=>{}),"(function(injectedScriptId){ ("+self.injectedExtensionAPI.toString()+")("+r+","+i+", injectedScriptId);})"};var p=Object.freeze({__proto__:null});class g{port;nextRequestId=0;pendingRequests;constructor(e){this.port=e,this.port.onmessage=this.onResponse.bind(this),this.pendingRequests=new Map}sendRequest(e,t){return new Promise(((n,s)=>{const i=this.nextRequestId++;this.pendingRequests.set(i,{resolve:n,reject:s}),this.port.postMessage({requestId:i,method:e,parameters:t})}))}disconnect(){for(const{reject:e}of this.pendingRequests.values())e(new Error("Extension endpoint disconnected"));this.pendingRequests.clear(),this.port.close()}onResponse({data:e}){if("event"in e)return void this.handleEvent(e);const{requestId:t,result:n,error:s}=e,i=this.pendingRequests.get(t);i?(this.pendingRequests.delete(t),s?i.reject(new Error(s.message)):i.resolve(n)):console.error(`No pending request ${t}`)}handleEvent(e){throw new Error("handleEvent is not implemented")}}var m=Object.freeze({__proto__:null,ExtensionEndpoint:g});class f extends e.Widget.Widget{server;id;iframe;frameIndex;constructor(e,t,n,s){super(),this.setHideOnDetach(),this.element.className="vbox flex-auto",this.element.tabIndex=-1,this.server=e,this.id=t,this.iframe=document.createElement("iframe"),this.iframe.addEventListener("load",this.onLoad.bind(this),!1),this.iframe.src=n,this.iframe.className=s,this.setDefaultFocusedElement(this.element),this.element.appendChild(this.iframe)}wasShown(){super.wasShown(),"number"==typeof this.frameIndex&&this.server.notifyViewShown(this.id,this.frameIndex)}willHide(){"number"==typeof this.frameIndex&&this.server.notifyViewHidden(this.id)}onLoad(){const e=window.frames;this.frameIndex=Array.prototype.indexOf.call(e,this.iframe.contentWindow),this.isShowing()&&this.server.notifyViewShown(this.id,this.frameIndex)}}class w extends e.Widget.VBox{server;id;constructor(e,t){super(),this.server=e,this.id=t}wasShown(){this.server.notifyViewShown(this.id)}willHide(){this.server.notifyViewHidden(this.id)}}var b=Object.freeze({__proto__:null,ExtensionNotifierView:w,ExtensionView:f});class R extends e.Panel.Panel{server;id;panelToolbar;searchableViewInternal;constructor(t,n,s,i){super(n),this.server=t,this.id=s,this.setHideOnDetach(),this.panelToolbar=this.element.createChild("devtools-toolbar","hidden"),this.searchableViewInternal=new e.SearchableView.SearchableView(this,null),this.searchableViewInternal.show(this.element);new f(t,this.id,i,"extension").show(this.searchableViewInternal.element)}addToolbarItem(e){this.panelToolbar.classList.remove("hidden"),this.panelToolbar.appendToolbarItem(e)}onSearchCanceled(){this.server.notifySearchAction(this.id,"cancelSearch"),this.searchableViewInternal.updateSearchMatchesCount(0)}searchableView(){return this.searchableViewInternal}performSearch(e,t,n){const s=e.query;this.server.notifySearchAction(this.id,"performSearch",s)}jumpToNextSearchResult(){this.server.notifySearchAction(this.id,"nextSearchResult")}jumpToPreviousSearchResult(){this.server.notifySearchAction(this.id,"previousSearchResult")}supportsCaseSensitiveSearch(){return!1}supportsRegexSearch(){return!1}}class E{id;toolbarButtonInternal;constructor(t,n,s,i,r){this.id=n,this.toolbarButtonInternal=new e.Toolbar.ToolbarButton("",""),this.toolbarButtonInternal.addEventListener("Click",t.notifyButtonClicked.bind(t,this.id)),this.update(s,i,r)}update(e,t,n){"string"==typeof e&&this.toolbarButtonInternal.setBackgroundImage(e),"string"==typeof t&&this.toolbarButtonInternal.setTitle(t),"boolean"==typeof n&&this.toolbarButtonInternal.setEnabled(!n)}toolbarButton(){return this.toolbarButtonInternal}}class x extends e.View.SimpleView{panelNameInternal;server;idInternal;extensionView;objectPropertiesView;constructor(e,t,n,s){super(n),this.element.classList.add("fill"),this.panelNameInternal=t,this.server=e,this.idInternal=s}id(){return this.idInternal}panelName(){return this.panelNameInternal}setObject(e,n,s){this.createObjectPropertiesView(),this.setObjectInternal(t.RemoteObject.RemoteObject.fromLocalObject(e),n,s)}setExpression(e,t,n,s,i){this.createObjectPropertiesView(),this.server.evaluate(e,!0,!1,n,s,this.onEvaluate.bind(this,t,i))}setPage(e){this.objectPropertiesView&&(this.objectPropertiesView.detach(),delete this.objectPropertiesView),this.extensionView&&this.extensionView.detach(!0),this.extensionView=new f(this.server,this.idInternal,e,"extension fill"),this.extensionView.show(this.element),this.element.style.height||this.setHeight("150px")}setHeight(e){this.element.style.height=e}onEvaluate(e,t,n,s,i){n?t(n.toString()):s?this.setObjectInternal(s,e,t):t()}createObjectPropertiesView(){this.objectPropertiesView||(this.extensionView&&(this.extensionView.detach(!0),delete this.extensionView),this.objectPropertiesView=new w(this.server,this.idInternal),this.objectPropertiesView.show(this.element))}setObjectInternal(t,n,s){const i=this.objectPropertiesView;i?(i.element.removeChildren(),e.UIUtils.Renderer.render(t,{title:n,editable:!1}).then((e=>{if(!e)return void s();const t=e.tree?.firstChild();t&&t.expand(),i.element.appendChild(e.node),s()}))):s("operation cancelled")}}var y=Object.freeze({__proto__:null,ExtensionButton:E,ExtensionPanel:R,ExtensionSidebarPane:x});function _(e){switch(e){case"http":return"80";case"https":return"443";case"ftp":return"25"}}class v{pattern;static parse(e){if("<all_urls>"===e)return new v({matchesAll:!0});const t=function(e){const t=e.indexOf("://");if(t<0)return;const n=e.substr(0,t).toLowerCase();return["*","http","https","ftp","chrome","chrome-extension"].includes(n)?{scheme:n,hostPattern:e.substr(t+3)}:void 0}(e);if(!t)return;const{scheme:n,hostPattern:s}=t,i=function(e,t){const n=e.indexOf("/");if(n>=0){const t=e.substr(n);if("/*"!==t&&"/"!==t)return;e=e.substr(0,n)}if(e.endsWith(":*")&&(e=e.substr(0,e.length-2)),e.endsWith(":"))return;let s;try{s=new URL(e.startsWith("*.")?`http://${e.substr(2)}`:`http://${e}`)}catch{return}if("/"!==s.pathname)return;if(s.hostname.endsWith(".")&&(s.hostname=s.hostname.substr(0,s.hostname.length-1)),"%2A"!==s.hostname&&s.hostname.includes("%2A"))return;const i=_("http");if(!i)return;const r=e.endsWith(`:${i}`)?i:""===s.port?"*":s.port;if("*"!==r&&!["http","https","ftp"].includes(t))return;return{host:"%2A"!==s.hostname?e.startsWith("*.")?`*.${s.hostname}`:s.hostname:"*",port:r}}(s,n);if(!i)return;const{host:r,port:o}=i;return new v({scheme:n,host:r,port:o,matchesAll:!1})}constructor(e){this.pattern=e}get scheme(){return this.pattern.matchesAll?"*":this.pattern.scheme}get host(){return this.pattern.matchesAll?"*":this.pattern.host}get port(){return this.pattern.matchesAll?"*":this.pattern.port}matchesAllUrls(){return this.pattern.matchesAll}matchesUrl(e){let t;try{t=new URL(e)}catch{return!1}if(this.matchesAllUrls())return!0;const n=t.protocol.substr(0,t.protocol.length-1),s=t.port||_(n);return this.matchesScheme(n)&&this.matchesHost(t.hostname)&&(!s||this.matchesPort(s))}matchesScheme(e){return!!this.pattern.matchesAll||("*"===this.pattern.scheme?"http"===e||"https"===e:this.pattern.scheme===e)}matchesHost(e){if(this.pattern.matchesAll)return!0;if("*"===this.pattern.host)return!0;let t=new URL(`http://${e}`).hostname;return t.endsWith(".")&&(t=t.substr(0,t.length-1)),this.pattern.host.startsWith("*.")?t===this.pattern.host.substr(2)||t.endsWith(this.pattern.host.substr(1)):this.pattern.host===t}matchesPort(e){return!!this.pattern.matchesAll||("*"===this.pattern.port||this.pattern.port===e)}}var I=Object.freeze({__proto__:null,HostUrlPattern:v});class A extends g{plugin;constructor(e,t){super(t),this.plugin=e}handleEvent({event:e}){switch(e){case"unregisteredLanguageExtensionPlugin":{this.disconnect();const{pluginManager:e}=d.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance();e.removePlugin(this.plugin);break}}}}class S{supportedScriptTypes;endpoint;extensionOrigin;allowFileAccess;name;constructor(e,t,n,s,i){this.name=n,this.extensionOrigin=t,this.supportedScriptTypes=s,this.endpoint=new A(this,i),this.allowFileAccess=e}canAccessURL(e){try{return!e||this.allowFileAccess||"file:"!==new URL(e).protocol}catch{return!0}}handleScript(e){try{if(!this.canAccessURL(e.contentURL())||e.hasSourceURL&&!this.canAccessURL(e.sourceURL)||e.debugSymbols?.externalURL&&!this.canAccessURL(e.debugSymbols.externalURL))return!1}catch{return!1}const t=e.scriptLanguage();return null!==t&&null!==e.debugSymbols&&t===this.supportedScriptTypes.language&&this.supportedScriptTypes.symbol_types.includes(e.debugSymbols.type)}createPageResourceLoadInitiator(){return{target:null,frameId:null,extensionId:this.extensionOrigin,initiatorUrl:this.extensionOrigin}}addRawModule(e,t,n){return this.canAccessURL(t)&&this.canAccessURL(n.url)?this.endpoint.sendRequest("addRawModule",{rawModuleId:e,symbolsURL:t,rawModule:n}):Promise.resolve([])}removeRawModule(e){return this.endpoint.sendRequest("removeRawModule",{rawModuleId:e})}sourceLocationToRawLocation(e){return this.endpoint.sendRequest("sourceLocationToRawLocation",{sourceLocation:e})}rawLocationToSourceLocation(e){return this.endpoint.sendRequest("rawLocationToSourceLocation",{rawLocation:e})}getScopeInfo(e){return this.endpoint.sendRequest("getScopeInfo",{type:e})}listVariablesInScope(e){return this.endpoint.sendRequest("listVariablesInScope",{rawLocation:e})}getFunctionInfo(e){return this.endpoint.sendRequest("getFunctionInfo",{rawLocation:e})}getInlinedFunctionRanges(e){return this.endpoint.sendRequest("getInlinedFunctionRanges",{rawLocation:e})}getInlinedCalleesRanges(e){return this.endpoint.sendRequest("getInlinedCalleesRanges",{rawLocation:e})}async getMappedLines(e,t){return await this.endpoint.sendRequest("getMappedLines",{rawModuleId:e,sourceFileURL:t})}async evaluate(e,t,n){return await this.endpoint.sendRequest("formatValue",{expression:e,context:t,stopId:n})}getProperties(e){return this.endpoint.sendRequest("getProperties",{objectId:e})}releaseObject(e){return this.endpoint.sendRequest("releaseObject",{objectId:e})}}var O=Object.freeze({__proto__:null,LanguageExtensionEndpoint:S});let L=null;class P extends n.ObjectWrapper.ObjectWrapper{#e=new Set;#t=new Map;static instance(){return L||(L=new P),L}addPlugin(e){this.#e.add(e),this.dispatchEventToListeners("pluginAdded",e)}removePlugin(e){this.#e.delete(e),this.dispatchEventToListeners("pluginRemoved",e)}plugins(){return Array.from(this.#e.values())}registerView(e){this.#t.set(e.id,e),this.dispatchEventToListeners("viewRegistered",e)}views(){return Array.from(this.#t.values())}getViewDescriptor(e){return this.#t.get(e)}showView(e){const t=this.#t.get(e);if(!t)throw new Error(`View with id ${e} is not found.`);this.dispatchEventToListeners("showViewRequested",t)}}var T=Object.freeze({__proto__:null,RecorderPluginManager:P});class C extends g{name;mediaType;capabilities;constructor(e,t,n,s){super(t),this.name=e,this.mediaType=s,this.capabilities=n}getName(){return this.name}getCapabilities(){return this.capabilities}getMediaType(){return this.mediaType}handleEvent({event:e}){if("unregisteredRecorderExtensionPlugin"!==e)throw new Error(`Unrecognized Recorder extension endpoint event: ${e}`);this.disconnect(),P.instance().removePlugin(this)}stringify(e){return this.sendRequest("stringify",{recording:e})}stringifyStep(e){return this.sendRequest("stringifyStep",{step:e})}replay(e){return this.sendRequest("replay",{recording:e})}}var H=Object.freeze({__proto__:null,RecorderExtensionEndpoint:C});const k=new WeakMap,U=["http:","https:","file:","data:","chrome-extension:","about:"];let M;class q{runtimeAllowedHosts;runtimeBlockedHosts;static create(e){const t=[],n=[];if(e){for(const n of e.runtimeAllowedHosts){const e=v.parse(n);if(!e)return null;t.push(e)}for(const t of e.runtimeBlockedHosts){const e=v.parse(t);if(!e)return null;n.push(e)}}return new q(t,n)}constructor(e,t){this.runtimeAllowedHosts=e,this.runtimeBlockedHosts=t}isAllowedOnURL(e){return e?!(this.runtimeBlockedHosts.some((t=>t.matchesUrl(e)))&&!this.runtimeAllowedHosts.some((t=>t.matchesUrl(e)))):0===this.runtimeBlockedHosts.length}}class D{name;hostsPolicy;allowFileAccess;constructor(e,t,n){this.name=e,this.hostsPolicy=t,this.allowFileAccess=n}isAllowedOnTarget(e){if(e||(e=t.TargetManager.TargetManager.instance().primaryPageTarget()?.inspectedURL()),!e)return!1;if(!F.canInspectURL(e))return!1;if(!this.hostsPolicy.isAllowedOnURL(e))return!1;if(!this.allowFileAccess){let t;try{t=new URL(e)}catch{return!1}return"file:"!==t.protocol}return!0}}class N{filter;constructor(e){this.filter=e}}class F extends n.ObjectWrapper.ObjectWrapper{clientObjects;handlers;subscribers;subscriptionStartHandlers;subscriptionStopHandlers;extraHeaders;requests;requestIds;lastRequestId;registeredExtensions;status;sidebarPanesInternal;extensionsEnabled;inspectedTabId;extensionAPITestHook;themeChangeHandlers=new Map;#n=[];constructor(){super(),this.clientObjects=new Map,this.handlers=new Map,this.subscribers=new Map,this.subscriptionStartHandlers=new Map,this.subscriptionStopHandlers=new Map,this.extraHeaders=new Map,this.requests=new Map,this.requestIds=new Map,this.lastRequestId=0,this.registeredExtensions=new Map,this.status=new W,this.sidebarPanesInternal=[],this.extensionsEnabled=!0,this.registerHandler("addRequestHeaders",this.onAddRequestHeaders.bind(this)),this.registerHandler("createPanel",this.onCreatePanel.bind(this)),this.registerHandler("createSidebarPane",this.onCreateSidebarPane.bind(this)),this.registerHandler("createToolbarButton",this.onCreateToolbarButton.bind(this)),this.registerHandler("evaluateOnInspectedPage",this.onEvaluateOnInspectedPage.bind(this)),this.registerHandler("_forwardKeyboardEvent",this.onForwardKeyboardEvent.bind(this)),this.registerHandler("getHAR",this.onGetHAR.bind(this)),this.registerHandler("getPageResources",this.onGetPageResources.bind(this)),this.registerHandler("getRequestContent",this.onGetRequestContent.bind(this)),this.registerHandler("getResourceContent",this.onGetResourceContent.bind(this)),this.registerHandler("Reload",this.onReload.bind(this)),this.registerHandler("setOpenResourceHandler",this.onSetOpenResourceHandler.bind(this)),this.registerHandler("setThemeChangeHandler",this.onSetThemeChangeHandler.bind(this)),this.registerHandler("setResourceContent",this.onSetResourceContent.bind(this)),this.registerHandler("attachSourceMapToResource",this.onAttachSourceMapToResource.bind(this)),this.registerHandler("setSidebarHeight",this.onSetSidebarHeight.bind(this)),this.registerHandler("setSidebarContent",this.onSetSidebarContent.bind(this)),this.registerHandler("setSidebarPage",this.onSetSidebarPage.bind(this)),this.registerHandler("showPanel",this.onShowPanel.bind(this)),this.registerHandler("subscribe",this.onSubscribe.bind(this)),this.registerHandler("openResource",this.onOpenResource.bind(this)),this.registerHandler("unsubscribe",this.onUnsubscribe.bind(this)),this.registerHandler("updateButton",this.onUpdateButton.bind(this)),this.registerHandler("registerLanguageExtensionPlugin",this.registerLanguageExtensionEndpoint.bind(this)),this.registerHandler("getWasmLinearMemory",this.onGetWasmLinearMemory.bind(this)),this.registerHandler("getWasmGlobal",this.onGetWasmGlobal.bind(this)),this.registerHandler("getWasmLocal",this.onGetWasmLocal.bind(this)),this.registerHandler("getWasmOp",this.onGetWasmOp.bind(this)),this.registerHandler("registerRecorderExtensionPlugin",this.registerRecorderExtensionEndpoint.bind(this)),this.registerHandler("reportResourceLoad",this.onReportResourceLoad.bind(this)),this.registerHandler("setFunctionRangesForScript",this.onSetFunctionRangesForScript.bind(this)),this.registerHandler("createRecorderView",this.onCreateRecorderView.bind(this)),this.registerHandler("showRecorderView",this.onShowRecorderView.bind(this)),this.registerHandler("showNetworkPanel",this.onShowNetworkPanel.bind(this)),window.addEventListener("message",this.onWindowMessage,!1);const e=window.DevToolsAPI?.getInspectedTabId?.();e&&this.setInspectedTabId({data:e}),s.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(s.InspectorFrontendHostAPI.Events.SetInspectedTabId,this.setInspectedTabId,this),this.initExtensions(),c.ThemeSupport.instance().addEventListener(c.ThemeChangeEvent.eventName,this.#s)}get isEnabledForTest(){return this.extensionsEnabled}dispose(){c.ThemeSupport.instance().removeEventListener(c.ThemeChangeEvent.eventName,this.#s),t.TargetManager.TargetManager.instance().removeEventListener("InspectedURLChanged",this.inspectedURLChanged,this),s.InspectorFrontendHost.InspectorFrontendHostInstance.events.removeEventListener(s.InspectorFrontendHostAPI.Events.SetInspectedTabId,this.setInspectedTabId,this),window.removeEventListener("message",this.onWindowMessage,!1)}#s=()=>{const e=c.ThemeSupport.instance().themeName();for(const t of this.themeChangeHandlers.values())t.postMessage({command:"host-theme-change",themeName:e})};static instance(e={forceNew:null}){const{forceNew:t}=e;return M&&!t||(M?.dispose(),M=new F),M}initializeExtensions(){null!==this.inspectedTabId&&s.InspectorFrontendHost.InspectorFrontendHostInstance.setAddExtensionCallback(this.addExtension.bind(this))}hasExtensions(){return Boolean(this.registeredExtensions.size)}notifySearchAction(e,t,n){this.postNotification("panel-search-"+e,[t,n])}notifyViewShown(e,t){this.postNotification("view-shown-"+e,[t])}notifyViewHidden(e){this.postNotification("view-hidden,"+e,[])}notifyButtonClicked(e){this.postNotification("button-clicked-"+e,[])}profilingStarted(){this.postNotification("profiling-started-",[])}profilingStopped(){this.postNotification("profiling-stopped-",[])}registerLanguageExtensionEndpoint(e,t){if("registerLanguageExtensionPlugin"!==e.command)return this.status.E_BADARG("command","expected registerLanguageExtensionPlugin");const{pluginManager:n}=d.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),{pluginName:s,port:i,supportedScriptTypes:{language:r,symbol_types:o}}=e,a=Array.isArray(o)&&o.every((e=>"string"==typeof e))?o:[],c=this.getExtensionOrigin(t),u=this.registeredExtensions.get(c);if(!u)throw new Error("Received a message from an unregistered extension");const l=new S(u.allowFileAccess,c,s,{language:r,symbol_types:a},i);return n.addPlugin(l),this.status.OK()}async loadWasmValue(e,t,n,s){const{pluginManager:i}=d.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),r=i.callFrameForStopId(s);if(!r)return this.status.E_BADARG("stopId","Unknown stop id");const o=await r.debuggerModel.agent.invoke_evaluateOnCallFrame({callFrameId:r.id,expression:n,silent:!0,returnByValue:!e,generatePreview:e,throwOnSideEffect:!0});return o.exceptionDetails||o.getError()?this.status.E_FAILED("Failed"):t(o.result)}async onGetWasmLinearMemory(e){return"getWasmLinearMemory"!==e.command?this.status.E_BADARG("command","expected getWasmLinearMemory"):await this.loadWasmValue(!1,(e=>e.value),`[].slice.call(new Uint8Array(memories[0].buffer, ${Number(e.offset)}, ${Number(e.length)}))`,e.stopId)}convertWasmValue(e,t){return n=>{if("undefined"===n.type)return;if("object"!==n.type||"wasmvalue"!==n.subtype)return this.status.E_FAILED("Bad object type");const s=n?.description,i=n.preview?.properties?.find((e=>"value"===e.name))?.value??"";switch(s){case"i32":case"f32":case"f64":return{type:s,value:Number(i)};case"i64":return{type:s,value:BigInt(i)};case"v128":return{type:s,value:i};default:return{type:"reftype",valueClass:e,index:t}}}}async onGetWasmGlobal(e){if("getWasmGlobal"!==e.command)return this.status.E_BADARG("command","expected getWasmGlobal");const t=Number(e.global);return await this.loadWasmValue(!0,this.convertWasmValue("global",t),`globals[${t}]`,e.stopId)??this.status.E_BADARG("global",`No global with index ${t}`)}async onGetWasmLocal(e){if("getWasmLocal"!==e.command)return this.status.E_BADARG("command","expected getWasmLocal");const t=Number(e.local);return await this.loadWasmValue(!0,this.convertWasmValue("local",t),`locals[${t}]`,e.stopId)??this.status.E_BADARG("local",`No local with index ${t}`)}async onGetWasmOp(e){if("getWasmOp"!==e.command)return this.status.E_BADARG("command","expected getWasmOp");const t=Number(e.op);return await this.loadWasmValue(!0,this.convertWasmValue("operand",t),`stack[${t}]`,e.stopId)??this.status.E_BADARG("op",`No operand with index ${t}`)}registerRecorderExtensionEndpoint(e,t){if("registerRecorderExtensionPlugin"!==e.command)return this.status.E_BADARG("command","expected registerRecorderExtensionPlugin");const{pluginName:n,mediaType:s,port:i,capabilities:r}=e;return P.instance().addPlugin(new C(n,i,r,s)),this.status.OK()}onReportResourceLoad(e){if("reportResourceLoad"!==e.command)return this.status.E_BADARG("command","expected reportResourceLoad");const{resourceUrl:n,extensionId:s,status:i}=e,r={url:n,initiator:{target:null,frameId:null,initiatorUrl:s,extensionId:s},errorMessage:i.errorMessage,success:i.success??null,size:i.size??null,duration:null};return t.PageResourceLoader.PageResourceLoader.instance().resourceLoadedThroughExtension(r),this.status.OK()}onSetFunctionRangesForScript(e,t){if("setFunctionRangesForScript"!==e.command)return this.status.E_BADARG("command","expected setFunctionRangesForScript");const{scriptUrl:n,ranges:s}=e;if(!n||!s?.length)return this.status.E_BADARG("command","expected valid scriptUrl and non-empty NamedFunctionRanges");if(!this.extensionAllowedOnURL(n,t))return this.status.E_FAILED("Permission denied");const i=h.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(n);if(!i)return this.status.E_NOTFOUND(n);if(!i.contentType().isScript()||!i.contentType().isFromSourceMap())return this.status.E_BADARG("command",`expected a source map script resource for url: ${n}`);try{d.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().setFunctionRanges(i,s)}catch(e){return this.status.E_FAILED(e)}return this.status.OK()}onShowRecorderView(e){if("showRecorderView"!==e.command)return this.status.E_BADARG("command","expected showRecorderView");P.instance().showView(e.id)}onShowNetworkPanel(e){return"showNetworkPanel"!==e.command?this.status.E_BADARG("command","expected showNetworkPanel"):(n.Revealer.reveal(new N(e.filter)),this.status.OK())}onCreateRecorderView(e,t){if("createRecorderView"!==e.command)return this.status.E_BADARG("command","expected createRecorderView");const n=e.id;if(this.clientObjects.has(n))return this.status.E_EXISTS(n);const s=F.expandResourcePath(this.getExtensionOrigin(t),e.pagePath);if(void 0===s)return this.status.E_BADARG("pagePath","Resources paths cannot point to non-extension resources");return P.instance().registerView({id:n,pagePath:s,title:e.title,onShown:()=>this.notifyViewShown(n),onHidden:()=>this.notifyViewHidden(n)}),this.status.OK()}inspectedURLChanged(e){if(!F.canInspectURL(e.data.inspectedURL()))return void this.disableExtensions();if(e.data!==t.TargetManager.TargetManager.instance().primaryPageTarget())return;this.requests=new Map,this.enableExtensions();const n=e.data.inspectedURL();this.postNotification("inspected-url-changed",[n]);this.#n.splice(0).forEach((e=>this.addExtension(e)))}hasSubscribers(e){return this.subscribers.has(e)}postNotification(e,t,n){if(!this.extensionsEnabled)return;const s=this.subscribers.get(e);if(!s)return;const i={command:"notify-"+e,arguments:t};for(const e of s)if(this.extensionEnabled(e)){if(n){const t=k.get(e),s=t&&this.registeredExtensions.get(t);if(!s||!n(s))continue}e.postMessage(i)}}onSubscribe(e,t){if("subscribe"!==e.command)return this.status.E_BADARG("command","expected subscribe");const n=this.subscribers.get(e.type);if(n)n.add(t);else{this.subscribers.set(e.type,new Set([t]));const n=this.subscriptionStartHandlers.get(e.type);n&&n()}}onUnsubscribe(e,t){if("unsubscribe"!==e.command)return this.status.E_BADARG("command","expected unsubscribe");const n=this.subscribers.get(e.type);if(n&&(n.delete(t),!n.size)){this.subscribers.delete(e.type);const t=this.subscriptionStopHandlers.get(e.type);t&&t()}}onAddRequestHeaders(e){if("addRequestHeaders"!==e.command)return this.status.E_BADARG("command","expected addRequestHeaders");const n=e.extensionId;if("string"!=typeof n)return this.status.E_BADARGTYPE("extensionId",typeof n,"string");let s=this.extraHeaders.get(n);s||(s=new Map,this.extraHeaders.set(n,s));for(const t in e.headers)s.set(t,e.headers[t]);const i={};for(const e of this.extraHeaders.values())for(const[t,n]of e)"__proto__"!==t&&"string"==typeof n&&(i[t]=n);t.NetworkManager.MultitargetNetworkManager.instance().setExtraHTTPHeaders(i)}getExtensionOrigin(e){const t=k.get(e);if(!t)throw new Error("Received a message from an unregistered extension");return t}onCreatePanel(t,n){if("createPanel"!==t.command)return this.status.E_BADARG("command","expected createPanel");const s=t.id;if(this.clientObjects.has(s)||e.InspectorView.InspectorView.instance().hasPanel(s))return this.status.E_EXISTS(s);const r=F.expandResourcePath(this.getExtensionOrigin(n),t.page);if(void 0===r)return this.status.E_BADARG("page","Resources paths cannot point to non-extension resources");let o=this.getExtensionOrigin(n)+t.title;o=o.replace(/\s|:\d+/g,"");const a=new j(o,i.i18n.lockedString(t.title),new R(this,o,s,r));return this.clientObjects.set(s,a),e.InspectorView.InspectorView.instance().addPanel(a),this.status.OK()}onShowPanel(t){if("showPanel"!==t.command)return this.status.E_BADARG("command","expected showPanel");let n=t.id;const s=this.clientObjects.get(t.id);s&&s instanceof j&&(n=s.viewId()),e.InspectorView.InspectorView.instance().showPanel(n)}onCreateToolbarButton(e,t){if("createToolbarButton"!==e.command)return this.status.E_BADARG("command","expected createToolbarButton");const n=this.clientObjects.get(e.panel);if(!(n&&n instanceof j))return this.status.E_NOTFOUND(e.panel);const s=F.expandResourcePath(this.getExtensionOrigin(t),e.icon);if(void 0===s)return this.status.E_BADARG("icon","Resources paths cannot point to non-extension resources");const i=new E(this,e.id,s,e.tooltip,e.disabled);return this.clientObjects.set(e.id,i),n.widget().then((function(e){e.addToolbarItem(i.toolbarButton())})),this.status.OK()}onUpdateButton(e,t){if("updateButton"!==e.command)return this.status.E_BADARG("command","expected updateButton");const n=this.clientObjects.get(e.id);if(!(n&&n instanceof E))return this.status.E_NOTFOUND(e.id);const s=e.icon&&F.expandResourcePath(this.getExtensionOrigin(t),e.icon);return e.icon&&void 0===s?this.status.E_BADARG("icon","Resources paths cannot point to non-extension resources"):(n.update(s,e.tooltip,e.disabled),this.status.OK())}onCreateSidebarPane(e){if("createSidebarPane"!==e.command)return this.status.E_BADARG("command","expected createSidebarPane");const t=e.id,n=new x(this,e.panel,i.i18n.lockedString(e.title),t);return this.sidebarPanesInternal.push(n),this.clientObjects.set(t,n),this.dispatchEventToListeners("SidebarPaneAdded",n),this.status.OK()}sidebarPanes(){return this.sidebarPanesInternal}onSetSidebarHeight(e){if("setSidebarHeight"!==e.command)return this.status.E_BADARG("command","expected setSidebarHeight");const t=this.clientObjects.get(e.id);return t&&t instanceof x?(t.setHeight(e.height),this.status.OK()):this.status.E_NOTFOUND(e.id)}onSetSidebarContent(e,t){if("setSidebarContent"!==e.command)return this.status.E_BADARG("command","expected setSidebarContent");const{requestId:n,id:s,rootTitle:i,expression:r,evaluateOptions:o,evaluateOnPage:a}=e,c=this.clientObjects.get(s);if(!(c&&c instanceof x))return this.status.E_NOTFOUND(e.id);function d(e){const s=e?this.status.E_FAILED(e):this.status.OK();this.dispatchCallback(n,t,s)}a?c.setExpression(r,i,o,this.getExtensionOrigin(t),d.bind(this)):c.setObject(e.expression,e.rootTitle,d.bind(this))}onSetSidebarPage(e,t){if("setSidebarPage"!==e.command)return this.status.E_BADARG("command","expected setSidebarPage");const n=this.clientObjects.get(e.id);if(!(n&&n instanceof x))return this.status.E_NOTFOUND(e.id);const s=F.expandResourcePath(this.getExtensionOrigin(t),e.page);if(void 0===s)return this.status.E_BADARG("page","Resources paths cannot point to non-extension resources");n.setPage(s)}onOpenResource(e){if("openResource"!==e.command)return this.status.E_BADARG("command","expected openResource");const t=h.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.url);if(t)return n.Revealer.reveal(t.uiLocation(e.lineNumber,e.columnNumber)),this.status.OK();const s=d.ResourceUtils.resourceForURL(e.url);if(s)return n.Revealer.reveal(s),this.status.OK();const i=o.NetworkLog.NetworkLog.instance().requestForURL(e.url);return i?(n.Revealer.reveal(i),this.status.OK()):this.status.E_NOTFOUND(e.url)}onSetOpenResourceHandler(e,t){if("setOpenResourceHandler"!==e.command)return this.status.E_BADARG("command","expected setOpenResourceHandler");const n=this.registeredExtensions.get(this.getExtensionOrigin(t));if(!n)throw new Error("Received a message from an unregistered extension");const{name:s}=n;e.handlerPresent?a.Linkifier.Linkifier.registerLinkHandler(s,this.handleOpenURL.bind(this,t)):a.Linkifier.Linkifier.unregisterLinkHandler(s)}onSetThemeChangeHandler(e,t){if("setThemeChangeHandler"!==e.command)return this.status.E_BADARG("command","expected setThemeChangeHandler");const n=this.getExtensionOrigin(t);if(!this.registeredExtensions.get(n))throw new Error("Received a message from an unregistered extension");e.handlerPresent?this.themeChangeHandlers.set(n,t):this.themeChangeHandlers.delete(n)}handleOpenURL(e,t,n){this.extensionAllowedOnURL(t.contentURL(),e)&&e.postMessage({command:"open-resource",resource:this.makeResource(t),lineNumber:n+1})}extensionAllowedOnURL(e,t){const n=k.get(t),s=n&&this.registeredExtensions.get(n);return Boolean(s?.isAllowedOnTarget(e))}extensionAllowedOnTarget(e,t){return this.extensionAllowedOnURL(e.inspectedURL(),t)}onReload(e,n){if("Reload"!==e.command)return this.status.E_BADARG("command","expected Reload");const s=e.options||{};let i;t.NetworkManager.MultitargetNetworkManager.instance().setUserAgentOverride("string"==typeof s.userAgent?s.userAgent:"",null),s.injectedScript&&(i="(function(){"+s.injectedScript+"})()");const r=t.TargetManager.TargetManager.instance().primaryPageTarget();if(!r)return this.status.OK();const o=r.model(t.ResourceTreeModel.ResourceTreeModel);return this.extensionAllowedOnTarget(r,n)?(o?.reloadPage(Boolean(s.ignoreCache),i),this.status.OK()):this.status.E_FAILED("Permission denied")}onEvaluateOnInspectedPage(e,t){if("evaluateOnInspectedPage"!==e.command)return this.status.E_BADARG("command","expected evaluateOnInspectedPage");const{requestId:n,expression:s,evaluateOptions:i}=e;return this.evaluate(s,!0,!0,i,this.getExtensionOrigin(t),function(e,s,i){let r;r=e||!s?this.status.E_PROTOCOLERROR(e?.toString()):i?{isException:!0,value:s.description}:{value:s.value},this.dispatchCallback(n,t,r)}.bind(this))}async onGetHAR(e,t){if("getHAR"!==e.command)return this.status.E_BADARG("command","expected getHAR");const n=o.NetworkLog.NetworkLog.instance().requests().filter((e=>this.extensionAllowedOnURL(e.url(),t))),s=await u.Log.Log.build(n,{sanitize:!1});for(let e=0;e<s.entries.length;++e)s.entries[e]._requestId=this.requestId(n[e]);return s}makeResource(e){return{url:e.contentURL(),type:e.contentType().name()}}onGetPageResources(e,n){const s=new Map;function i(e){return!s.has(e.contentURL())&&this.extensionAllowedOnURL(e.contentURL(),n)&&s.set(e.contentURL(),this.makeResource(e)),!1}let r=h.Workspace.WorkspaceImpl.instance().uiSourceCodesForProjectType(h.Workspace.projectTypes.Network);r=r.concat(h.Workspace.WorkspaceImpl.instance().uiSourceCodesForProjectType(h.Workspace.projectTypes.ContentScripts)),r.forEach(i.bind(this));for(const e of t.TargetManager.TargetManager.instance().models(t.ResourceTreeModel.ResourceTreeModel))this.extensionAllowedOnTarget(e.target(),n)&&e.forAllResources(i.bind(this));return[...s.values()]}async getResourceContent(e,t,n){if(!this.extensionAllowedOnURL(e.contentURL(),n))return void this.dispatchCallback(t.requestId,n,this.status.E_FAILED("Permission denied"));const s=await e.requestContentData();if(l.ContentData.ContentData.isError(s))return void this.dispatchCallback(t.requestId,n,{encoding:"",content:null});const i=s.isTextContent?"":"base64",r=s.isTextContent?s.text:s.base64;this.dispatchCallback(t.requestId,n,{encoding:i,content:r})}onGetRequestContent(e,t){if("getRequestContent"!==e.command)return this.status.E_BADARG("command","expected getRequestContent");const n=this.requestById(e.id);if(!n)return this.status.E_NOTFOUND(e.id);this.getResourceContent(n,e,t)}onGetResourceContent(e,t){if("getResourceContent"!==e.command)return this.status.E_BADARG("command","expected getResourceContent");const n=e.url,s=h.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(n)||d.ResourceUtils.resourceForURL(n);if(!s)return this.status.E_NOTFOUND(n);this.getResourceContent(s,e,t)}onAttachSourceMapToResource(e,t){if("attachSourceMapToResource"!==e.command)return this.status.E_BADARG("command","expected getResourceContent");if(!e.sourceMapURL)return this.status.E_FAILED("Expected a source map URL but got null");const n=e.contentUrl;if(!this.extensionAllowedOnURL(n,t))return this.status.E_FAILED("Permission denied");const s=h.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(n);if(!s)return this.status.E_NOTFOUND(n);const i=d.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),r=i.scriptsForUISourceCode(s);if(r.length>0)for(const t of r){const n=i.scriptFile(s,t.debuggerModel);n?.addSourceMapURL(e.sourceMapURL)}return this.status.OK()}onSetResourceContent(e,n){if("setResourceContent"!==e.command)return this.status.E_BADARG("command","expected setResourceContent");const{url:s,requestId:i,content:r,commit:o}=e;if(!this.extensionAllowedOnURL(s,n))return this.status.E_FAILED("Permission denied");const a=h.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(s);if(!a?.contentType().isDocumentOrScriptOrStyleSheet()){return t.ResourceTreeModel.ResourceTreeModel.resourceForURL(s)?this.status.E_NOTSUPPORTED("Resource is not editable"):this.status.E_NOTFOUND(s)}a.setWorkingCopy(r),o&&a.commitWorkingCopy(),function(e){const t=e?this.status.E_FAILED(e):this.status.OK();this.dispatchCallback(i,n,t)}.call(this,null)}requestId(e){const t=this.requestIds.get(e);if(void 0===t){const t=++this.lastRequestId;return this.requestIds.set(e,t),this.requests.set(t,e),t}return t}requestById(e){r