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