var expectedWindowProperty,Common;!function(e){!function(s){"use strict";class t{constructor(e){this._messageHandlers=[];this._pendingMessages=[];this._pendingMessagesMap={};this._portId=0;this._uid=0;this.childrenElementLimit=200;this.onDetachCallback=null;this.port=null;this.portReady=!1;this._messageHandlers=e}static getDefaultView(e){return e?void 0!==e.defaultView?e.defaultView:e.parentWindow:null}getUid(){return"uid"+(this._uid++).toString(36)}initialize(e,s,t){this.onDetachCallback=t;browser.addEventListener("documentComplete",this.onDocumentComplete.bind(this));toolUI.addEventListener("detach",this.onDetach.bind(this));toolUI.addEventListener("breakpointhit",this.onBreak.bind(this));++this._portId;this.port=toolUI.createPort(e+this._portId);if(this.port){this.port.addEventListener("message",this.processMessages.bind(this));toolUI.connect(this.port);s()}this._handshakeCallback=s}initializeScriptEngines(s){if(s){if(s.document&&s.document.scripts&&0===s.document.scripts.length)try{e.RemoteHelpers.executeScript("",s,!0)}catch(e){}if(s.frames)for(var t=0;t<s.frames.length;t++){var i=s.frames[t];if(dom.isWindow(i)){var n=dom.getCrossSiteWindow(s,i);this.initializeScriptEngines(n)}}}}postAllMessages(){for(var e in this._pendingMessagesMap)this._pendingMessages.push(this._pendingMessagesMap[e]);if(this._pendingMessages.length>0){var s=JSON.stringify(this._pendingMessages);this._pendingMessages=[];this._pendingMessagesMap={};try{this.port.postMessage(s)}catch(e){return}}}processMessages(e){if("InitializeDocument"!==e.data)for(var s=e=>{var s=(s,t)=>{this.postObject({uid:e,args:[s]},t)};s.uid=e;return s},t=JSON.parse(e.data),i=0;i<t.length;++i){var n=t[i];if(this._messageHandlers[n.command]){for(var a=n.args,o=0;o<a.length;++o)a[o]&&"callback"===a[o].type&&(a[o]=s(a[o].uid));var r=this._messageHandlers[n.command].apply(this,a);this.postObject({uid:n.uid,args:void 0!==r?[r]:void 0})}}else this._handshakeCallback()}onBreak(){this.postAllMessages()}onDetach(){this._uid=0;this._pendingMessages=[];this._pendingMessagesMap={};this.onDetachCallback&&this.onDetachCallback()}onDocumentComplete(s){if(expectedWindowProperty){var t=null;if(s)try{s.browserOrWindow&&(s=s.browserOrWindow);s.document?t=s.document:s.Document&&(t=s.Document);var i=e.PerfTools.__BROWSERTOOLS_RemoteHelper.getDefaultView(t);if(!t||i[expectedWindowProperty])return;e.RemoteHelpers.executeScript("",i,!0)}catch(e){}}}postObject(e,s,t=!0){s?this._pendingMessagesMap[s]=e:this._pendingMessages.push(e);this.postAllMessages()}}t.JMCScriptUrl="\\r\\n//# sourceURL=browsertools://browsertools.performance.js";t.InitializeDocumentMaxTries=15;t.InitializeDocumentTries=0;s.__BROWSERTOOLS_RemoteHelper=t}(e.PerfTools||(e.PerfTools={}))}(Common||(Common={}));
