Audits2.LighthouseResult;Audits2.WorkerResult;Audits2.Audits2Panel=class extends UI.Panel{constructor(){super('audits2');this.setHideOnDetach();this.registerRequiredCSS('audits2/audits2Panel.css');this._protocolService=new Audits2.ProtocolService();this._protocolService.registerStatusCallback(msg=>this._updateStatus(Common.UIString(msg)));this._pwaSetting=Common.settings.createSetting('audits2_pwa',true);this._perfSetting=Common.settings.createSetting('audits2_perf',true);this._practicesSetting=Common.settings.createSetting('audits2_best_practices',true);var auditsViewElement=this.contentElement.createChild('div','hbox audits-view');this._resultsView=this.contentElement.createChild('div','vbox results-view');auditsViewElement.appendChild(createElementWithClass('div','audits2-logo'));auditsViewElement.appendChild(this._createLauncherUI());}
_reset(){this.contentElement.classList.remove('show-results');this._resultsView.removeChildren();}
_createSettingCheckbox(name,setting){const checkboxItem=new UI.ToolbarCheckbox(name,undefined,setting);return checkboxItem;}
_createLauncherUI(){var uiElement=createElement('div');var headerElement=uiElement.createChild('header');headerElement.createChild('p').textContent=Common.UIString('Audits will analyze the page against modern development best practices and collect useful performance metrics and diagnostics. Select audits to collect:');uiElement.appendChild(headerElement);var auditSelectorForm=uiElement.createChild('form','audits2-form');var perfCheckbox=this._createSettingCheckbox(Common.UIString('Performance metrics and diagnostics'),this._perfSetting);var pwaCheckbox=this._createSettingCheckbox(Common.UIString('Progressive web app audits'),this._pwaSetting);var practicesCheckbox=this._createSettingCheckbox(Common.UIString('Modern web development best practices'),this._practicesSetting);[perfCheckbox,practicesCheckbox,pwaCheckbox].forEach(checkbox=>auditSelectorForm.appendChild(checkbox.element));this._startButton=UI.createTextButton(Common.UIString('Audit this page'),this._startButtonClicked.bind(this),'run-audit audit-btn');auditSelectorForm.appendChild(this._startButton);this._statusView=this._createStatusView();uiElement.appendChild(this._statusView);return uiElement;}
_createStatusView(){var statusView=createElementWithClass('div','audits2-status hbox hidden');statusView.createChild('span','icon');this._statusElement=createElement('p');statusView.appendChild(this._statusElement);this._updateStatus(Common.UIString('Loading...'));return statusView;}
_start(){this._auditRunning=true;this._updateButton();this._updateStatus(Common.UIString('Loading...'));this._inspectedURL=SDK.targetManager.mainTarget().inspectedURL();const aggregationTags=[this._pwaSetting,this._perfSetting,this._practicesSetting].map(setting=>({id:setting.name.replace('audits2_',''),value:setting.get()}));return Promise.resolve().then(_=>this._protocolService.attach()).then(_=>this._protocolService.startLighthouse(this._inspectedURL,aggregationTags)).then(workerResult=>{this._finish(workerResult);return this._stop();});}
_startButtonClicked(event){if(this._auditRunning){this._updateStatus(Common.UIString('Cancelling...'));this._stop();return;}
this._start();}
_updateButton(){this._startButton.textContent=this._auditRunning?Common.UIString('Cancel audit'):Common.UIString('Audit this page');this._startButton.classList.toggle('started',this._auditRunning);this._statusView.classList.toggle('hidden',!this._auditRunning);}
_updateStatus(statusMessage){this._statusElement.textContent=statusMessage;}
_stop(){return this._protocolService.detach().then(_=>{this._auditRunning=false;this._updateButton();if(this._inspectedURL!==SDK.targetManager.mainTarget().inspectedURL())
SDK.targetManager.mainTarget().pageAgent().navigate(this._inspectedURL);});}
_finish(workerResult){if(workerResult===null){this._updateStatus(Common.UIString('Auditing failed.'));return;}
this._resultsView.removeChildren();this._resultsView.appendChild(this._createResultsBar(workerResult.result.url,workerResult.result.generatedTime));this._resultsView.appendChild(this._createIframe(workerResult.blobUrl));this.contentElement.classList.add('show-results');}
_createIframe(blobUrl){var iframeContainer=createElementWithClass('div','iframe-container');var iframe=iframeContainer.createChild('iframe','fill');iframe.setAttribute('sandbox','allow-scripts allow-popups-to-escape-sandbox allow-popups');iframe.src=blobUrl;return iframeContainer;}
_createResultsBar(url,timestamp){var elem=createElementWithClass('div','results-bar hbox');elem.createChild('div','audits2-logo audits2-logo-small');var summaryElem=elem.createChild('div','audits2-summary');var reportFor=summaryElem.createChild('span');reportFor.createTextChild('Report for ');var urlElem=reportFor.createChild('b');urlElem.textContent=url;var timeElem=summaryElem.createChild('span');timeElem.textContent=`Generated at ${new Date(timestamp).toLocaleDateString()} ${new Date(timestamp).toLocaleTimeString()}`;var newAuditButton=UI.createTextButton(Common.UIString('New Audit'),this._reset.bind(this),'new-audit audit-btn');elem.appendChild(newAuditButton);return elem;}};Audits2.ProtocolService=class extends Common.Object{constructor(){super();this._rawConnection=null;this._backend=null;this._backendPromise=null;this._status=null;}
attach(){return SDK.targetManager.interceptMainConnection(this._dispatchProtocolMessage.bind(this)).then(rawConnection=>{this._rawConnection=rawConnection;});}
startLighthouse(inspectedURL,aggregationTags){return this._send('start',{url:inspectedURL,aggregationTags});}
detach(){return Promise.resolve().then(()=>this._send('stop')).then(()=>this._backend.dispose()).then(()=>{delete this._backend;delete this._backendPromise;return this._rawConnection.disconnect();});}
registerStatusCallback(callback){this._status=callback;}
_dispatchProtocolMessage(message){this._send('dispatchProtocolMessage',{message:message});}
_initWorker(){this._backendPromise=Services.serviceManager.createAppService('audits2_worker','Audits2Service',false).then(backend=>{if(this._backend)
return;this._backend=backend;this._backend.on('statusUpdate',result=>this._status(result.message));this._backend.on('sendProtocolMessage',result=>this._rawConnection.sendMessage(result.message));});}
_send(method,params){if(!this._backendPromise)
this._initWorker();return this._backendPromise.then(_=>this._backend.send(method,params));}};;Runtime.cachedResources["audits2/audits2Panel.css"]="/*\n * Copyright (C) 2008 Apple Inc.  All rights reserved.\n * Copyright (C) 2009 Google Inc. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n *     * Redistributions in binary form must reproduce the above\n * copyright notice, this list of conditions and the following disclaimer\n * in the documentation and/or other materials provided with the\n * distribution.\n *     * Neither the name of Google Inc. nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\niframe {\n    width: 100%;\n    height: 100%;\n    flex-direction: column !important;\n    position: relative;\n    flex: auto;\n}\n\n.audits-view {\n    max-width: 550px;\n    min-width: 334px;\n    align-self: center;\n    margin-top: 30px;\n    margin: 30px 20px;\n}\n\n.results-view {\n    display: none;\n    flex-wrap: nowrap;\n    justify-content: flex-start;\n    align-content: stretch;\n    align-items: stretch;\n}\n\n.show-results .audits-view {\n    display: none;\n}\n\n.show-results .results-view {\n    display: flex;\n    flex: 1;\n}\n\n.results-bar {\n    flex: 0 0;\n    align-self: auto;\n    border-bottom: 1px solid #cccccc;\n}\n\n.audits2-summary {display: flex;flex-direction: column;flex-grow: 1;padding: 6px;line-height: 1.7;align-self: center;}\n\n.audits2-summary span {\n    color: #b7b7b7;\n    display: block;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n}\n\n.audits2-summary span b {\n    font-weight: normal;\n    color: #636382;\n}\n\n.audits2-summary span:first-child {\n    color: inherit;\n    font-size: 110%;\n}\n\n.audits2-logo {\n    width: 100px;\n    height: 110px;\n    flex-shrink: 0;\n    background-repeat: no-repeat;\n    background-size: contain;\n    margin-top: 10px;\n    background-image: -webkit-image-set(\n        url(Images/audits_logo.png) 1x,\n        url(Images/audits_logo_2x.png) 2x);\n}\n\n.audits2-logo-small {\n    background-image: -webkit-image-set(\n        url(Images/audits_logo_bw.png) 1x,\n        url(Images/audits_logo_bw_2x.png) 2x);\n    height: 41px;\n    width: 42px;\n    align-self: center;\n    margin: 0 0 0 20px;\n    flex-shrink: 0;\n}\n\n.iframe-container {\n    flex: 1 1 auto;\n    align-self: auto;\n    position: relative;\n}\n\n.audits2-form label {\n    display: block;\n}\n\n.audits2-form label div {\n    display: inline;\n}\n\nbutton.audit-btn {\n    display: inline-block;\n    font-family: BlinkMacSystemFont, '.SFNSDisplay-Regular', 'Helvetica Neue', 'Lucida Grande', sans-serif;\n    color: white;\n    text-shadow: none;\n    padding: 6px 10px;\n    background-color: #4285f4 !important;\n    background-image: unset !important;\n    font-size: 11px;\n    box-shadow: none !important;\n}\n\nbutton.audit-btn:hover {\n    background-color: hsla(217, 89%, 58%, 1) !important;\n    color: white !important;\n}\n\nbutton.run-audit {\n    margin-top: 12px;\n}\nbutton.run-audit.started {\n    background-color: #ffffff !important;\n    color: gray;\n}\n\nbutton.run-audit.started:hover {\n    background-color: #eee !important;\n    color: gray !important;\n}\n\nbutton.new-audit {\n    align-self: center;\n    margin-right: 20px;\n}\n\n.audits2-status .icon {\n    width: 16px;\n    height: 16px;\n    margin-top: 10px;\n    margin-right: 4px;\n    animation: spinner-animation 1200ms linear infinite;\n    transform-origin: 50% 50%;\n    padding: 1px;\n}\n\n.audits2-status .icon::before {\n    display: inline-block;\n    border: 1px solid #1565C0;\n    border-radius: 7px;\n    width: 14px;\n    height: 14px;\n    content: \"\";\n    position: absolute;\n    box-sizing: border-box;\n}\n\n.audits2-status .icon::after {\n    display: inline-block;\n    width: 6px;\n    height: 7px;\n    background: white;\n    position: absolute;\n    content: \"\";\n}\n\n@keyframes spinner-animation {\n    from { transform: rotate(0); }\n    to { transform: rotate(360deg); }\n\n/*# sourceURL=audits2/audits2Panel.css */";