OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @unrestricted | 6 * @unrestricted |
7 */ | 7 */ |
8 Audits2.Audits2Panel = class extends UI.Panel { | 8 Audits2.Audits2Panel = class extends UI.Panel { |
9 constructor() { | 9 constructor() { |
10 super('audits2'); | 10 super('audits2'); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 this._statusView = this._createStatusView(uiElement); | 55 this._statusView = this._createStatusView(uiElement); |
56 } | 56 } |
57 | 57 |
58 /** | 58 /** |
59 * @param {!Element} launcherUIElement | 59 * @param {!Element} launcherUIElement |
60 * @return {!Element} | 60 * @return {!Element} |
61 */ | 61 */ |
62 _createStatusView(launcherUIElement) { | 62 _createStatusView(launcherUIElement) { |
63 var statusView = launcherUIElement.createChild('div', 'audits2-status hbox h
idden'); | 63 var statusView = launcherUIElement.createChild('div', 'audits2-status hbox h
idden'); |
64 statusView.createChild('span', 'icon'); | 64 this._statusIcon = statusView.createChild('span', 'icon'); |
65 this._statusElement = createElement('p'); | 65 this._statusElement = statusView.createChild('p'); |
66 statusView.appendChild(this._statusElement); | |
67 this._updateStatus(Common.UIString('Loading...')); | 66 this._updateStatus(Common.UIString('Loading...')); |
68 return statusView; | 67 return statusView; |
69 } | 68 } |
70 | 69 |
71 _start() { | 70 _start() { |
72 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); | 71 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); |
73 | 72 |
74 const categoryIDs = this._settings.map(setting => { | 73 const categoryIDs = this._settings.map(setting => { |
75 const preset = Audits2.Audits2Panel.Presets.find(preset => preset.id === s
etting.name); | 74 const preset = Audits2.Audits2Panel.Presets.find(preset => preset.id === s
etting.name); |
76 return {configID: preset.configID, value: setting.get()}; | 75 return {configID: preset.configID, value: setting.get()}; |
77 }).filter(agg => !!agg.value).map(agg => agg.configID); | 76 }).filter(agg => !!agg.value).map(agg => agg.configID); |
78 | 77 |
79 return Promise.resolve() | 78 return Promise.resolve() |
80 .then(_ => this._protocolService.attach()) | 79 .then(_ => this._protocolService.attach()) |
81 .then(_ => { | 80 .then(_ => { |
82 this._auditRunning = true; | 81 this._auditRunning = true; |
83 this._updateButton(); | 82 this._updateButton(); |
84 this._updateStatus(Common.UIString('Loading...')); | 83 this._updateStatus(Common.UIString('Loading...')); |
85 }) | 84 }) |
86 .then(_ => this._protocolService.startLighthouse(this._inspectedURL, cat
egoryIDs)) | 85 .then(_ => this._protocolService.startLighthouse(this._inspectedURL, cat
egoryIDs)) |
87 .then(lighthouseResult => { | 86 .then(lighthouseResult => { |
88 this._finish(lighthouseResult); | 87 this._finish(lighthouseResult); |
89 return this._stop(); | 88 return this._stop(); |
| 89 }).catch(err => { |
| 90 if (err instanceof Error) this._renderBugReport(err); |
90 }); | 91 }); |
91 } | 92 } |
92 | 93 |
93 /** | 94 /** |
94 * @param {!Event} event | 95 * @param {!Event} event |
95 */ | 96 */ |
96 _startButtonClicked(event) { | 97 _startButtonClicked(event) { |
97 if (this._auditRunning) { | 98 if (this._auditRunning) { |
98 this._updateStatus(Common.UIString('Cancelling...')); | 99 this._updateStatus(Common.UIString('Cancelling...')); |
99 this._stop(); | 100 this._stop(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 this._resultsView.removeChildren(); | 142 this._resultsView.removeChildren(); |
142 | 143 |
143 var url = lighthouseResult.url; | 144 var url = lighthouseResult.url; |
144 var timestamp = lighthouseResult.generatedTime; | 145 var timestamp = lighthouseResult.generatedTime; |
145 this._createResultsBar(this._resultsView, url, timestamp); | 146 this._createResultsBar(this._resultsView, url, timestamp); |
146 this._renderReport(this._resultsView, lighthouseResult); | 147 this._renderReport(this._resultsView, lighthouseResult); |
147 this.contentElement.classList.add('show-results'); | 148 this.contentElement.classList.add('show-results'); |
148 } | 149 } |
149 | 150 |
150 /** | 151 /** |
| 152 * @param {!Error} err |
| 153 */ |
| 154 _renderBugReport(err) { |
| 155 console.error(err); |
| 156 this._statusElement.textContent = ''; |
| 157 this._statusIcon.classList.add('error'); |
| 158 this._statusElement.createTextChild(Common.UIString('We ran into an error. '
)); |
| 159 this._createBugReportLink(err, this._statusElement); |
| 160 } |
| 161 |
| 162 /** |
| 163 * @param {!Error} err |
| 164 * @param {!Element} parentElem |
| 165 */ |
| 166 _createBugReportLink(err, parentElem) { |
| 167 var baseURI = 'https://github.com/GoogleChrome/lighthouse/issues/new?'; |
| 168 var title = encodeURI('title=DevTools Error: ' + err.message.substring(0, 60
)); |
| 169 |
| 170 var qsBody = ''; |
| 171 qsBody += '**Error Message**: ' + err.message + '\n'; |
| 172 qsBody += '**Stack Trace**:\n ```' + err.stack + '```'; |
| 173 var body = '&body=' + encodeURI(qsBody); |
| 174 |
| 175 var reportErrorEl = parentElem.createChild('a', 'audits2-link audits2-report
-error'); |
| 176 reportErrorEl.href = baseURI + title + body; |
| 177 reportErrorEl.textContent = Common.UIString('Report this bug'); |
| 178 reportErrorEl.target = '_blank'; |
| 179 } |
| 180 |
| 181 /** |
151 * @param {!Element} resultsView | 182 * @param {!Element} resultsView |
152 * @param {!ReportRenderer.ReportJSON} lighthouseResult | 183 * @param {!ReportRenderer.ReportJSON} lighthouseResult |
153 * @suppressGlobalPropertiesCheck | 184 * @suppressGlobalPropertiesCheck |
154 */ | 185 */ |
155 _renderReport(resultsView, lighthouseResult) { | 186 _renderReport(resultsView, lighthouseResult) { |
156 var reportContainer = resultsView.createChild('div', 'report-container'); | 187 var reportContainer = resultsView.createChild('div', 'report-container lh-ro
ot'); |
157 | 188 |
158 var dom = new DOM(document); | 189 var dom = new DOM(document); |
159 var detailsRenderer = new DetailsRenderer(dom); | 190 var detailsRenderer = new DetailsRenderer(dom); |
160 var renderer = new ReportRenderer(dom, detailsRenderer); | 191 var categoryRenderer = new CategoryRenderer(dom, detailsRenderer); |
| 192 var renderer = new Audits2.ReportRenderer(dom, categoryRenderer); |
161 | 193 |
162 var templatesHTML = Runtime.cachedResources['audits2/lighthouse/templates.ht
ml']; | 194 var templatesHTML = Runtime.cachedResources['audits2/lighthouse/templates.ht
ml']; |
163 var templatesDOM = new DOMParser().parseFromString(templatesHTML, 'text/html
'); | 195 var templatesDOM = new DOMParser().parseFromString(templatesHTML, 'text/html
'); |
164 if (!templatesDOM) | 196 if (!templatesDOM) |
165 return; | 197 return; |
166 | 198 |
167 renderer.setTemplateContext(templatesDOM); | 199 renderer.setTemplateContext(templatesDOM); |
168 reportContainer.appendChild(renderer.renderReport(lighthouseResult)); | 200 renderer.renderReport(lighthouseResult, reportContainer); |
169 } | 201 } |
170 | 202 |
171 /** | 203 /** |
172 * @param {!Element} resultsView | 204 * @param {!Element} resultsView |
173 * @param {string} url | 205 * @param {string} url |
174 * @param {string} timestamp | 206 * @param {string} timestamp |
175 */ | 207 */ |
176 _createResultsBar(resultsView, url, timestamp) { | 208 _createResultsBar(resultsView, url, timestamp) { |
177 var elem = resultsView.createChild('div', 'results-bar hbox'); | 209 var elem = resultsView.createChild('div', 'results-bar hbox'); |
178 elem.createChild('div', 'audits2-logo audits2-logo-small'); | 210 elem.createChild('div', 'audits2-logo audits2-logo-small'); |
179 | 211 |
180 var summaryElem = elem.createChild('div', 'audits2-summary'); | 212 var summaryElem = elem.createChild('div', 'audits2-summary'); |
181 var reportFor = summaryElem.createChild('span'); | 213 var reportFor = summaryElem.createChild('span'); |
182 reportFor.createTextChild('Report for '); | 214 reportFor.createTextChild('Report for '); |
183 var urlElem = reportFor.createChild('b'); | 215 var urlElem = reportFor.createChild('b'); |
184 urlElem.textContent = url; | 216 urlElem.textContent = url; |
185 var timeElem = summaryElem.createChild('span'); | 217 var timeElem = summaryElem.createChild('span'); |
186 timeElem.textContent = | 218 timeElem.textContent = |
187 `Generated at ${new Date(timestamp).toLocaleDateString()} ${new Date(tim
estamp).toLocaleTimeString()}`; | 219 `Generated at ${new Date(timestamp).toLocaleDateString()} ${new Date(tim
estamp).toLocaleTimeString()}`; |
188 | 220 |
189 var newAuditButton = | 221 var newAuditButton = |
190 UI.createTextButton(Common.UIString('New Audit'), this._reset.bind(this)
, 'new-audit audit-btn'); | 222 UI.createTextButton(Common.UIString('New Audit'), this._reset.bind(this)
, 'new-audit audit-btn'); |
191 elem.appendChild(newAuditButton); | 223 elem.appendChild(newAuditButton); |
192 } | 224 } |
193 }; | 225 }; |
194 | 226 |
| 227 /** |
| 228 * @override |
| 229 */ |
| 230 Audits2.ReportRenderer = class extends ReportRenderer { |
| 231 /** |
| 232 * Provides empty element for left nav |
| 233 * @override |
| 234 * @returns {!DocumentFragment} |
| 235 */ |
| 236 _renderReportNav() { |
| 237 return createDocumentFragment(); |
| 238 } |
| 239 }; |
| 240 |
| 241 |
| 242 class ReportUIFeatures { |
| 243 /** |
| 244 * @param {!ReportRenderer.ReportJSON} report |
| 245 */ |
| 246 initFeatures(report) {} |
| 247 } |
| 248 |
195 /** @typedef {{id: string, configID: string, description: string}} */ | 249 /** @typedef {{id: string, configID: string, description: string}} */ |
196 Audits2.Audits2Panel.Preset; | 250 Audits2.Audits2Panel.Preset; |
197 | 251 |
198 /** @type {!Array.<!Audits2.Audits2Panel.Preset>} */ | 252 /** @type {!Array.<!Audits2.Audits2Panel.Preset>} */ |
199 Audits2.Audits2Panel.Presets = [ | 253 Audits2.Audits2Panel.Presets = [ |
200 // configID maps to Lighthouse's Object.keys(config.categories)[0] value | 254 // configID maps to Lighthouse's Object.keys(config.categories)[0] value |
201 {id: 'audits2_cat_pwa', configID: 'pwa', description: 'Progressive Web App'}, | 255 {id: 'audits2_cat_pwa', configID: 'pwa', description: 'Progressive Web App'}, |
202 {id: 'audits2_cat_perf', configID: 'performance', description: 'Performance me
trics and diagnostics'}, | 256 {id: 'audits2_cat_perf', configID: 'performance', description: 'Performance me
trics and diagnostics'}, |
203 {id: 'audits2_cat_a11y', configID: 'accessibility', description: 'Accessibilit
y'}, | 257 {id: 'audits2_cat_a11y', configID: 'accessibility', description: 'Accessibilit
y'}, |
204 {id: 'audits2_cat_best_practices', configID: 'best-practices', description: 'M
odern best practices'}, | 258 {id: 'audits2_cat_best_practices', configID: 'best-practices', description: 'M
odern best practices'}, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 * @param {!Object=} params | 330 * @param {!Object=} params |
277 * @return {!Promise<!ReportRenderer.ReportJSON>} | 331 * @return {!Promise<!ReportRenderer.ReportJSON>} |
278 */ | 332 */ |
279 _send(method, params) { | 333 _send(method, params) { |
280 if (!this._backendPromise) | 334 if (!this._backendPromise) |
281 this._initWorker(); | 335 this._initWorker(); |
282 | 336 |
283 return this._backendPromise.then(_ => this._backend.send(method, params)); | 337 return this._backendPromise.then(_ => this._backend.send(method, params)); |
284 } | 338 } |
285 }; | 339 }; |
OLD | NEW |