Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 5 | export default class StatusView { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 6 | /** |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 7 | * @param {!Audits.AuditController} controller |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 8 | */ |
| 9 | constructor(controller) { |
| 10 | this._controller = controller; |
| 11 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 12 | this._statusView = null; |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 13 | this._statusHeader = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 14 | this._progressWrapper = null; |
| 15 | this._progressBar = null; |
| 16 | this._statusText = null; |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 17 | this._cancelButton = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 18 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 19 | this._inspectedURL = ''; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 20 | this._textChangedAt = 0; |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 21 | this._fastFactsQueued = FastFacts.slice(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 22 | this._currentPhase = null; |
| 23 | this._scheduledTextChangeTimeout = null; |
| 24 | this._scheduledFastFactTimeout = null; |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 25 | |
| 26 | this._dialog = new UI.Dialog(); |
Patrick Hulce | 8d387f1 | 2018-05-29 18:54:54 +0000 | [diff] [blame] | 27 | this._dialog.setDimmed(true); |
| 28 | this._dialog.setCloseOnEscape(false); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 29 | this._dialog.setOutsideClickCallback(event => event.consume(true)); |
| 30 | this._render(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 33 | _render() { |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 34 | const dialogRoot = UI.createShadowRootWithCoreStyles(this._dialog.contentElement, 'audits/auditsDialog.css'); |
| 35 | const auditsViewElement = dialogRoot.createChild('div', 'audits-view vbox'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 36 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 37 | const cancelButton = UI.createTextButton(ls`Cancel`, this._cancel.bind(this)); |
| 38 | const fragment = UI.Fragment.build` |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 39 | <div class="audits-view vbox"> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 40 | <h2 $="status-header">Auditing your web page\u2026</h2> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 41 | <div class="audits-status vbox" $="status-view"> |
| 42 | <div class="audits-progress-wrapper" $="progress-wrapper"> |
| 43 | <div class="audits-progress-bar" $="progress-bar"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 44 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 45 | <div class="audits-status-text" $="status-text"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 46 | </div> |
| 47 | ${cancelButton} |
| 48 | </div> |
| 49 | `; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 50 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 51 | auditsViewElement.appendChild(fragment.element()); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 52 | |
| 53 | this._statusView = fragment.$('status-view'); |
| 54 | this._statusHeader = fragment.$('status-header'); |
| 55 | this._progressWrapper = fragment.$('progress-wrapper'); |
| 56 | this._progressBar = fragment.$('progress-bar'); |
| 57 | this._statusText = fragment.$('status-text'); |
John Emau | 69c3876 | 2019-11-25 18:17:47 -0800 | [diff] [blame] | 58 | // Use StatusPhases array index as progress bar value |
| 59 | UI.ARIAUtils.markAsProgressBar(this._progressBar, 0, Audits.StatusView.StatusPhases.length - 1); |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 60 | this._cancelButton = cancelButton; |
John Emau | 463280d | 2019-07-19 00:37:40 +0000 | [diff] [blame] | 61 | UI.ARIAUtils.markAsStatus(this._statusText); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 62 | |
| 63 | this._dialog.setDefaultFocusedElement(cancelButton); |
| 64 | this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeight); |
| 65 | this._dialog.setMaxContentSize(new UI.Size(500, 400)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 68 | _reset() { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 69 | this._resetProgressBarClasses(); |
| 70 | clearTimeout(this._scheduledFastFactTimeout); |
| 71 | |
| 72 | this._textChangedAt = 0; |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 73 | this._fastFactsQueued = FastFacts.slice(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 74 | this._currentPhase = null; |
| 75 | this._scheduledTextChangeTimeout = null; |
| 76 | this._scheduledFastFactTimeout = null; |
| 77 | } |
| 78 | |
| 79 | /** |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 80 | * @param {!Element} dialogRenderElement |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 81 | */ |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 82 | show(dialogRenderElement) { |
| 83 | this._reset(); |
| 84 | this.updateStatus(ls`Loading\u2026`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 85 | |
Peter Marshall | 3e4e569 | 2019-12-09 17:48:04 +0100 | [diff] [blame^] | 86 | const parsedURL = Common.ParsedURL.fromString(this._inspectedURL); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 87 | const pageHost = parsedURL && parsedURL.host; |
| 88 | const statusHeader = pageHost ? ls`Auditing ${pageHost}` : ls`Auditing your web page`; |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 89 | this._renderStatusHeader(statusHeader); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 90 | this._dialog.show(dialogRenderElement); |
| 91 | } |
| 92 | |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 93 | /** |
| 94 | * @param {string=} statusHeader |
| 95 | */ |
| 96 | _renderStatusHeader(statusHeader) { |
| 97 | this._statusHeader.textContent = `${statusHeader}\u2026`; |
| 98 | } |
| 99 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 100 | hide() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 101 | if (this._dialog.isShowing()) { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 102 | this._dialog.hide(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 103 | } |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @param {string=} url |
| 108 | */ |
| 109 | setInspectedURL(url = '') { |
| 110 | this._inspectedURL = url; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @param {?string} message |
| 115 | */ |
| 116 | updateStatus(message) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 117 | if (!message || !this._statusText) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 118 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 119 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 120 | |
| 121 | if (message.startsWith('Cancel')) { |
| 122 | this._commitTextChange(Common.UIString('Cancelling\u2026')); |
| 123 | clearTimeout(this._scheduledFastFactTimeout); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | const nextPhase = this._getPhaseForMessage(message); |
John Emau | 69c3876 | 2019-11-25 18:17:47 -0800 | [diff] [blame] | 128 | const nextPhaseIndex = Audits.StatusView.StatusPhases.indexOf(nextPhase); |
| 129 | const currentPhaseIndex = Audits.StatusView.StatusPhases.indexOf(this._currentPhase); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 130 | if (!nextPhase && !this._currentPhase) { |
| 131 | this._commitTextChange(Common.UIString('Lighthouse is warming up\u2026')); |
| 132 | clearTimeout(this._scheduledFastFactTimeout); |
John Emau | 69c3876 | 2019-11-25 18:17:47 -0800 | [diff] [blame] | 133 | } else if (nextPhase && (!this._currentPhase || currentPhaseIndex < nextPhaseIndex)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 134 | this._currentPhase = nextPhase; |
John Emau | 69c3876 | 2019-11-25 18:17:47 -0800 | [diff] [blame] | 135 | const text = this._getMessageForPhase(nextPhase); |
| 136 | this._scheduleTextChange(text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 137 | this._scheduleFastFactCheck(); |
| 138 | this._resetProgressBarClasses(); |
| 139 | this._progressBar.classList.add(nextPhase.progressBarClass); |
John Emau | 69c3876 | 2019-11-25 18:17:47 -0800 | [diff] [blame] | 140 | UI.ARIAUtils.setProgressBarValue(this._progressBar, nextPhaseIndex, text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 144 | _cancel() { |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 145 | this._controller.dispatchEventToListeners(Audits.Events.RequestAuditCancel); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 148 | /** |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 149 | * @param {!Audits.StatusView.StatusPhases} phase |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 150 | * @return {string} |
| 151 | */ |
| 152 | _getMessageForPhase(phase) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 153 | if (phase.message) { |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 154 | return phase.message; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 155 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 156 | |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 157 | const deviceType = Audits.RuntimeSettings.find(item => item.setting.name === 'audits.device_type').setting.get(); |
| 158 | const throttling = Audits.RuntimeSettings.find(item => item.setting.name === 'audits.throttling').setting.get(); |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 159 | const match = LoadingMessages.find(item => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 160 | return item.deviceType === deviceType && item.throttling === throttling; |
| 161 | }); |
| 162 | |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 163 | return match ? match.message : ls`Lighthouse is loading your page`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @param {string} message |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 168 | * @return {?Audits.StatusView.StatusPhases} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 169 | */ |
| 170 | _getPhaseForMessage(message) { |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 171 | return StatusPhases.find(phase => message.startsWith(phase.statusMessagePrefix)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | _resetProgressBarClasses() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 175 | if (!this._progressBar) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 176 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 177 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 178 | |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 179 | this._progressBar.className = 'audits-progress-bar'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | _scheduleFastFactCheck() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 183 | if (!this._currentPhase || this._scheduledFastFactTimeout) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 184 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 185 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 186 | |
| 187 | this._scheduledFastFactTimeout = setTimeout(() => { |
| 188 | this._updateFastFactIfNecessary(); |
| 189 | this._scheduledFastFactTimeout = null; |
| 190 | |
| 191 | this._scheduleFastFactCheck(); |
| 192 | }, 100); |
| 193 | } |
| 194 | |
| 195 | _updateFastFactIfNecessary() { |
| 196 | const now = performance.now(); |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 197 | if (now - this._textChangedAt < fastFactRotationInterval) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 198 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 199 | } |
| 200 | if (!this._fastFactsQueued.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 201 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 202 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 203 | |
| 204 | const fastFactIndex = Math.floor(Math.random() * this._fastFactsQueued.length); |
| 205 | this._scheduleTextChange(ls`\ud83d\udca1 ${this._fastFactsQueued[fastFactIndex]}`); |
| 206 | this._fastFactsQueued.splice(fastFactIndex, 1); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * @param {string} text |
| 211 | */ |
| 212 | _commitTextChange(text) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 213 | if (!this._statusText) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 214 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 215 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 216 | this._textChangedAt = performance.now(); |
| 217 | this._statusText.textContent = text; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * @param {string} text |
| 222 | */ |
| 223 | _scheduleTextChange(text) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 224 | if (this._scheduledTextChangeTimeout) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 225 | clearTimeout(this._scheduledTextChangeTimeout); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 226 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 227 | |
| 228 | const msSinceLastChange = performance.now() - this._textChangedAt; |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 229 | const msToTextChange = minimumTextVisibilityDuration - msSinceLastChange; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 230 | |
| 231 | this._scheduledTextChangeTimeout = setTimeout(() => { |
| 232 | this._commitTextChange(text); |
| 233 | }, Math.max(msToTextChange, 0)); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * @param {!Error} err |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 238 | */ |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 239 | renderBugReport(err) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 240 | console.error(err); |
| 241 | clearTimeout(this._scheduledFastFactTimeout); |
| 242 | clearTimeout(this._scheduledTextChangeTimeout); |
| 243 | this._resetProgressBarClasses(); |
| 244 | this._progressBar.classList.add('errored'); |
| 245 | |
| 246 | this._commitTextChange(''); |
Paul Irish | f265907 | 2019-03-24 19:08:52 +0000 | [diff] [blame] | 247 | this._statusText.createChild('p').createTextChild(Common.UIString('Ah, sorry! We ran into an error.')); |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 248 | if (KnownBugPatterns.some(pattern => pattern.test(err.message))) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 249 | const message = Common.UIString( |
Lorne Mitchell | 7aa2c6c | 2019-04-03 03:50:10 +0000 | [diff] [blame] | 250 | 'Try to navigate to the URL in a fresh Chrome profile without any other tabs or extensions open and try again.'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 251 | this._statusText.createChild('p').createTextChild(message); |
| 252 | } else { |
Paul Irish | f265907 | 2019-03-24 19:08:52 +0000 | [diff] [blame] | 253 | this._renderBugReportBody(err, this._inspectedURL); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 258 | * @param {string} statusHeader |
| 259 | * @param {string} text |
| 260 | */ |
| 261 | renderText(statusHeader, text) { |
| 262 | this._renderStatusHeader(statusHeader); |
| 263 | this._commitTextChange(text); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * @param {boolean} show |
| 268 | */ |
| 269 | toggleCancelButton(show) { |
| 270 | this._cancelButton.style.visibility = show ? 'visible' : 'hidden'; |
| 271 | } |
| 272 | |
| 273 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 274 | * @param {!Error} err |
| 275 | * @param {string} auditURL |
| 276 | */ |
Paul Irish | f265907 | 2019-03-24 19:08:52 +0000 | [diff] [blame] | 277 | _renderBugReportBody(err, auditURL) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 278 | const issueBody = ` |
Paul Irish | f265907 | 2019-03-24 19:08:52 +0000 | [diff] [blame] | 279 | ${err.message} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 280 | \`\`\` |
Paul Irish | f265907 | 2019-03-24 19:08:52 +0000 | [diff] [blame] | 281 | Channel: DevTools |
| 282 | Initial URL: ${auditURL} |
| 283 | Chrome Version: ${navigator.userAgent.match(/Chrome\/(\S+)/)[1]} |
| 284 | Stack Trace: ${err.stack} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 285 | \`\`\` |
Paul Irish | f265907 | 2019-03-24 19:08:52 +0000 | [diff] [blame] | 286 | `; |
| 287 | this._statusText.createChild('p').createTextChild( |
| 288 | ls`If this issue is reproducible, please report it at the Lighthouse GitHub repo.`); |
| 289 | this._statusText.createChild('code', 'monospace').createTextChild(issueBody.trim()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 290 | } |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 291 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 292 | |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 293 | /** @const */ |
| 294 | export const fastFactRotationInterval = 6000; |
| 295 | |
| 296 | /** @const */ |
| 297 | export const minimumTextVisibilityDuration = 3000; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 298 | |
| 299 | /** @type {!Array.<!RegExp>} */ |
Tim van der Lippe | c96ccd9 | 2019-11-29 16:23:54 +0000 | [diff] [blame] | 300 | const KnownBugPatterns = [ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 301 | /PARSING_PROBLEM/, |
| 302 | /DOCUMENT_REQUEST/, |
| 303 | /READ_FAILED/, |
| 304 | /TRACING_ALREADY_STARTED/, |
| 305 | /^You must provide a url to the runner/, |
| 306 | /^You probably have multiple tabs open/, |
| 307 | ]; |
| 308 | |
John Emau | 69c3876 | 2019-11-25 18:17:47 -0800 | [diff] [blame] | 309 | /** @typedef {{message: string, progressBarClass: string}} */ |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 310 | export const StatusPhases = [ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 311 | { |
| 312 | id: 'loading', |
| 313 | progressBarClass: 'loading', |
| 314 | statusMessagePrefix: 'Loading page', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 315 | }, |
| 316 | { |
| 317 | id: 'gathering', |
| 318 | progressBarClass: 'gathering', |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 319 | message: ls`Lighthouse is gathering information about the page to compute your score.`, |
cjamcl@google.com | f2f8c09 | 2019-05-30 22:01:56 +0000 | [diff] [blame] | 320 | statusMessagePrefix: 'Gathering', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 321 | }, |
| 322 | { |
| 323 | id: 'auditing', |
| 324 | progressBarClass: 'auditing', |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 325 | message: ls`Almost there! Lighthouse is now generating your report.`, |
cjamcl@google.com | f2f8c09 | 2019-05-30 22:01:56 +0000 | [diff] [blame] | 326 | statusMessagePrefix: 'Auditing', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 327 | } |
| 328 | ]; |
| 329 | |
| 330 | /** @typedef {{message: string, deviceType: string, throttling: string}} */ |
Tim van der Lippe | c96ccd9 | 2019-11-29 16:23:54 +0000 | [diff] [blame] | 331 | const LoadingMessages = [ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 332 | { |
| 333 | deviceType: 'mobile', |
| 334 | throttling: 'on', |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 335 | message: ls`Lighthouse is loading your page with throttling to measure performance on a mobile device on 3G.`, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 336 | }, |
| 337 | { |
| 338 | deviceType: 'desktop', |
| 339 | throttling: 'on', |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 340 | message: ls`Lighthouse is loading your page with throttling to measure performance on a slow desktop on 3G.`, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 341 | }, |
| 342 | { |
| 343 | deviceType: 'mobile', |
| 344 | throttling: 'off', |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 345 | message: ls`Lighthouse is loading your page with mobile emulation.`, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 346 | }, |
| 347 | { |
| 348 | deviceType: 'desktop', |
| 349 | throttling: 'off', |
Mandy Chen | ef16e33 | 2019-09-08 05:02:45 +0000 | [diff] [blame] | 350 | message: ls`Lighthouse is loading your page.`, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 351 | }, |
| 352 | ]; |
| 353 | |
Tim van der Lippe | c96ccd9 | 2019-11-29 16:23:54 +0000 | [diff] [blame] | 354 | const FastFacts = [ |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 355 | ls |
| 356 | `1MB takes a minimum of 5 seconds to download on a typical 3G connection [Source: WebPageTest and DevTools 3G definition].`, |
| 357 | ls`Rebuilding Pinterest pages for performance increased conversion rates by 15% [Source: WPO Stats]`, |
| 358 | ls`BBC has seen a loss of 10% of their users for every extra second of page load [Source: WPO Stats]`, ls |
| 359 | `By reducing the response size of JSON needed for displaying comments, Instagram saw increased impressions [Source: WPO Stats]`, |
| 360 | ls`Walmart saw a 1% increase in revenue for every 100ms improvement in page load [Source: WPO Stats]`, ls |
| 361 | `If a site takes >1 second to become interactive, users lose attention, and their perception of completing the page task is broken [Source: Google Developers Blog]`, |
| 362 | ls`75% of global mobile users in 2016 were on 2G or 3G [Source: GSMA Mobile]`, |
| 363 | ls`The average user device costs less than 200 USD. [Source: International Data Corporation]`, |
| 364 | ls`53% of all site visits are abandoned if page load takes more than 3 seconds [Source: Google DoubleClick blog]`, |
| 365 | ls |
| 366 | `19 seconds is the average time a mobile web page takes to load on a 3G connection [Source: Google DoubleClick blog]`, |
| 367 | ls |
| 368 | `14 seconds is the average time a mobile web page takes to load on a 4G connection [Source: Google DoubleClick blog]`, |
| 369 | ls |
| 370 | `70% of mobile pages take nearly 7 seconds for the visual content above the fold to display on the screen. [Source: Think with Google]`, |
| 371 | ls |
| 372 | `As page load time increases from one second to seven seconds, the probability of a mobile site visitor bouncing increases 113%. [Source: Think with Google]`, |
| 373 | ls |
| 374 | `As the number of elements on a page increases from 400 to 6,000, the probability of conversion drops 95%. [Source: Think with Google]`, |
| 375 | ls`70% of mobile pages weigh over 1MB, 36% over 2MB, and 12% over 4MB. [Source: Think with Google]`, ls |
| 376 | `Lighthouse only simulates mobile performance; to measure performance on a real device, try WebPageTest.org [Source: Lighthouse team]`, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 377 | ]; |
| 378 | |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 379 | /* Legacy exported object */ |
| 380 | self.Audits = self.Audits || {}; |
| 381 | |
| 382 | /* Legacy exported object */ |
| 383 | Audits = Audits || {}; |
| 384 | |
| 385 | /** |
Tim van der Lippe | c96ccd9 | 2019-11-29 16:23:54 +0000 | [diff] [blame] | 386 | * @constructor |
| 387 | */ |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 388 | Audits.StatusView = StatusView; |
| 389 | |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 390 | /** @typedef {{message: string, progressBarClass: string, order: number}} */ |
| 391 | Audits.StatusView.StatusPhases = StatusPhases; |