Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +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 | |
Tim van der Lippe | 7696157 | 2021-04-06 11:48:07 +0100 | [diff] [blame] | 5 | import * as Common from '../../core/common/common.js'; |
Tim van der Lippe | e024731 | 2021-04-01 15:25:30 +0100 | [diff] [blame] | 6 | import * as Host from '../../core/host/host.js'; |
Tim van der Lippe | bb352e6 | 2021-04-01 18:57:28 +0100 | [diff] [blame] | 7 | import * as i18n from '../../core/i18n/i18n.js'; |
Tim van der Lippe | aa1ed7a | 2021-03-31 15:38:27 +0100 | [diff] [blame] | 8 | import * as Platform from '../../core/platform/platform.js'; |
Tim van der Lippe | d8caac4 | 2021-03-31 15:40:44 +0100 | [diff] [blame] | 9 | import * as Root from '../../core/root/root.js'; |
Tim van der Lippe | e00b92f | 2021-03-31 17:52:17 +0100 | [diff] [blame] | 10 | import * as SDK from '../../core/sdk/sdk.js'; |
Tim van der Lippe | 99aeaf3 | 2021-04-09 11:33:34 +0100 | [diff] [blame] | 11 | import * as Workspace from '../../models/workspace/workspace.js'; |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 12 | import * as LighthouseReport from '../../third_party/lighthouse/report/report.js'; |
Tim van der Lippe | 339ad26 | 2021-04-21 13:23:36 +0100 | [diff] [blame] | 13 | import * as Components from '../../ui/legacy/components/utils/utils.js'; |
Tim van der Lippe | aa61faf | 2021-04-07 16:32:07 +0100 | [diff] [blame] | 14 | import * as UI from '../../ui/legacy/legacy.js'; |
Tim van der Lippe | fddcf40 | 2021-04-19 14:00:29 +0100 | [diff] [blame] | 15 | import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js'; |
Tim van der Lippe | 01e1c46 | 2021-04-19 16:04:03 +0100 | [diff] [blame] | 16 | import * as Timeline from '../timeline/timeline.js'; |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 17 | import type {RunnerResultArtifacts, NodeDetailsJSON, SourceLocationDetailsJSON} from './LighthouseReporterTypes.js'; |
Tim van der Lippe | 1e10f85 | 2020-10-30 14:35:01 +0000 | [diff] [blame] | 18 | |
Simon Zünd | 6f95e84 | 2021-03-01 08:41:55 +0100 | [diff] [blame] | 19 | const UIStrings = { |
vidorteg | 0684002 | 2020-11-20 21:18:03 -0800 | [diff] [blame] | 20 | /** |
| 21 | *@description Label for view trace button when simulated throttling is enabled |
| 22 | */ |
| 23 | viewOriginalTrace: 'View Original Trace', |
| 24 | /** |
| 25 | *@description Text of the timeline button in Lighthouse Report Renderer |
| 26 | */ |
| 27 | viewTrace: 'View Trace', |
| 28 | /** |
| 29 | *@description Help text for 'View Trace' button |
| 30 | */ |
| 31 | thePerformanceMetricsAboveAre: |
| 32 | 'The performance metrics above are simulated and won\'t match the timings found in this trace. Disable simulated throttling in "Lighthouse Settings" if you want the timings to match.', |
| 33 | }; |
Tim van der Lippe | 7a077eb | 2021-03-23 18:02:11 +0000 | [diff] [blame] | 34 | const str_ = i18n.i18n.registerUIStrings('panels/lighthouse/LighthouseReportRenderer.ts', UIStrings); |
vidorteg | 0684002 | 2020-11-20 21:18:03 -0800 | [diff] [blame] | 35 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 36 | const MaxLengthForLinks = 40; |
| 37 | |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 38 | export class LighthouseReportRenderer extends LighthouseReport.ReportRenderer { |
| 39 | constructor(dom: LighthouseReport.DOM) { |
Tim van der Lippe | 4df32c9 | 2020-11-06 12:35:05 +0000 | [diff] [blame] | 40 | super(dom); |
| 41 | } |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 42 | |
Connor Clark | 4cef932 | 2021-05-18 02:04:00 -0700 | [diff] [blame] | 43 | static addViewTraceButton( |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 44 | el: Element, reportUIFeatures: LighthouseReport.ReportUIFeatures, artifacts?: RunnerResultArtifacts): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 45 | if (!artifacts || !artifacts.traces || !artifacts.traces.defaultPass) { |
Paul Irish | 8f1e33d | 2018-05-31 02:29:50 +0000 | [diff] [blame] | 46 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 47 | } |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 48 | |
Adam Raine | f46d158 | 2020-08-17 20:24:32 +0000 | [diff] [blame] | 49 | const simulated = artifacts.settings.throttlingMethod === 'simulate'; |
cjamcl@google.com | 21d2d22 | 2019-08-09 01:58:17 +0000 | [diff] [blame] | 50 | const container = el.querySelector('.lh-audit-group'); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 51 | if (!container) { |
| 52 | return; |
| 53 | } |
Paul Irish | bf20468 | 2020-05-13 16:11:37 -0700 | [diff] [blame] | 54 | const disclaimerEl = container.querySelector('.lh-metrics__disclaimer'); |
| 55 | // If it was a PWA-only run, we'd have a trace but no perf category to add the button to |
| 56 | if (!disclaimerEl) { |
cjamcl@google.com | 21d2d22 | 2019-08-09 01:58:17 +0000 | [diff] [blame] | 57 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 58 | } |
cjamcl@google.com | 21d2d22 | 2019-08-09 01:58:17 +0000 | [diff] [blame] | 59 | |
Paul Irish | 8f1e33d | 2018-05-31 02:29:50 +0000 | [diff] [blame] | 60 | const defaultPassTrace = artifacts.traces.defaultPass; |
Connor Clark | 4cef932 | 2021-05-18 02:04:00 -0700 | [diff] [blame] | 61 | const text = simulated ? i18nString(UIStrings.viewOriginalTrace) : i18nString(UIStrings.viewTrace); |
| 62 | const timelineButton = reportUIFeatures.addButton({ |
| 63 | text, |
| 64 | onClick: onViewTraceClick, |
| 65 | }); |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 66 | if (timelineButton) { |
| 67 | timelineButton.classList.add('lh-button--trace'); |
| 68 | if (simulated) { |
| 69 | UI.Tooltip.Tooltip.install(timelineButton, i18nString(UIStrings.thePerformanceMetricsAboveAre)); |
| 70 | } |
Adam Raine | f46d158 | 2020-08-17 20:24:32 +0000 | [diff] [blame] | 71 | } |
Paul Irish | 8f1e33d | 2018-05-31 02:29:50 +0000 | [diff] [blame] | 72 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 73 | async function onViewTraceClick(): Promise<void> { |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 74 | Host.userMetrics.actionTaken(Host.UserMetrics.Action.LighthouseViewTrace); |
Tim van der Lippe | 80d8265 | 2020-08-27 14:53:44 +0100 | [diff] [blame] | 75 | await UI.InspectorView.InspectorView.instance().showPanel('timeline'); |
Paul Lewis | daac106 | 2020-03-05 14:37:10 +0000 | [diff] [blame] | 76 | Timeline.TimelinePanel.TimelinePanel.instance().loadFromEvents(defaultPassTrace.traceEvents); |
Paul Irish | 8f1e33d | 2018-05-31 02:29:50 +0000 | [diff] [blame] | 77 | } |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 78 | } |
cjamcl@google.com | da0e4c6 | 2018-11-27 23:52:10 +0000 | [diff] [blame] | 79 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 80 | static async linkifyNodeDetails(el: Element): Promise<void> { |
Sigurd Schneider | b9f6c79 | 2021-05-31 12:57:24 +0200 | [diff] [blame] | 81 | const mainTarget = SDK.TargetManager.TargetManager.instance().mainTarget(); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 82 | if (!mainTarget) { |
| 83 | return; |
| 84 | } |
Paul Lewis | daac106 | 2020-03-05 14:37:10 +0000 | [diff] [blame] | 85 | const domModel = mainTarget.model(SDK.DOMModel.DOMModel); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 86 | if (!domModel) { |
| 87 | return; |
| 88 | } |
cjamcl@google.com | da0e4c6 | 2018-11-27 23:52:10 +0000 | [diff] [blame] | 89 | |
| 90 | for (const origElement of el.getElementsByClassName('lh-node')) { |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 91 | const origHTMLElement = origElement as HTMLElement; |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 92 | const detailsItem = origHTMLElement.dataset as unknown as NodeDetailsJSON; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 93 | if (!detailsItem.path) { |
cjamcl@google.com | 5c46b7e | 2018-12-04 14:44:47 +0000 | [diff] [blame] | 94 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 95 | } |
cjamcl@google.com | da0e4c6 | 2018-11-27 23:52:10 +0000 | [diff] [blame] | 96 | |
| 97 | const nodeId = await domModel.pushNodeByPathToFrontend(detailsItem.path); |
| 98 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 99 | if (!nodeId) { |
cjamcl@google.com | 5c46b7e | 2018-12-04 14:44:47 +0000 | [diff] [blame] | 100 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 101 | } |
cjamcl@google.com | da0e4c6 | 2018-11-27 23:52:10 +0000 | [diff] [blame] | 102 | const node = domModel.nodeForId(nodeId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 103 | if (!node) { |
cjamcl@google.com | 5c46b7e | 2018-12-04 14:44:47 +0000 | [diff] [blame] | 104 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 105 | } |
cjamcl@google.com | da0e4c6 | 2018-11-27 23:52:10 +0000 | [diff] [blame] | 106 | |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 107 | const element = await Common.Linkifier.Linkifier.linkify( |
| 108 | node, {tooltip: detailsItem.snippet, preventKeyboardFocus: undefined}); |
Tim van der Lippe | 70842f3 | 2020-11-23 16:56:57 +0000 | [diff] [blame] | 109 | UI.Tooltip.Tooltip.install(origHTMLElement, ''); |
Connor Clark | 49872c0 | 2020-12-16 13:39:28 -0600 | [diff] [blame] | 110 | |
| 111 | const screenshotElement = origHTMLElement.querySelector('.lh-element-screenshot'); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 112 | origHTMLElement.textContent = ''; |
Connor Clark | 49872c0 | 2020-12-16 13:39:28 -0600 | [diff] [blame] | 113 | if (screenshotElement) { |
| 114 | origHTMLElement.append(screenshotElement); |
| 115 | } |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 116 | origHTMLElement.appendChild(element); |
cjamcl@google.com | da0e4c6 | 2018-11-27 23:52:10 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
cjamcl@google.com | f2f8c09 | 2019-05-30 22:01:56 +0000 | [diff] [blame] | 119 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 120 | static async linkifySourceLocationDetails(el: Element): Promise<void> { |
Connor Clark | 0403a42 | 2019-11-18 18:03:18 -0800 | [diff] [blame] | 121 | for (const origElement of el.getElementsByClassName('lh-source-location')) { |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 122 | const origHTMLElement = origElement as HTMLElement; |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 123 | const detailsItem = origHTMLElement.dataset as SourceLocationDetailsJSON; |
Connor Clark | 0403a42 | 2019-11-18 18:03:18 -0800 | [diff] [blame] | 124 | if (!detailsItem.sourceUrl || !detailsItem.sourceLine || !detailsItem.sourceColumn) { |
| 125 | continue; |
| 126 | } |
| 127 | const url = detailsItem.sourceUrl; |
| 128 | const line = Number(detailsItem.sourceLine); |
| 129 | const column = Number(detailsItem.sourceColumn); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 130 | const element = await Components.Linkifier.Linkifier.linkifyURL(url, { |
| 131 | lineNumber: line, |
| 132 | columnNumber: column, |
Philip Pfaffe | 068b01d | 2021-03-22 10:46:26 +0100 | [diff] [blame] | 133 | inlineFrameIndex: 0, |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 134 | maxLength: MaxLengthForLinks, |
| 135 | bypassURLTrimming: undefined, |
| 136 | className: undefined, |
| 137 | preventClick: undefined, |
| 138 | tabStop: undefined, |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 139 | text: undefined, |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 140 | }); |
Tim van der Lippe | 70842f3 | 2020-11-23 16:56:57 +0000 | [diff] [blame] | 141 | UI.Tooltip.Tooltip.install(origHTMLElement, ''); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 142 | origHTMLElement.textContent = ''; |
| 143 | origHTMLElement.appendChild(element); |
Connor Clark | 0403a42 | 2019-11-18 18:03:18 -0800 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 147 | static handleDarkMode(el: Element): void { |
Paul Lewis | ca569a5 | 2020-09-09 17:11:51 +0100 | [diff] [blame] | 148 | if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') { |
cjamcl@google.com | f2f8c09 | 2019-05-30 22:01:56 +0000 | [diff] [blame] | 149 | el.classList.add('dark'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 150 | } |
cjamcl@google.com | f2f8c09 | 2019-05-30 22:01:56 +0000 | [diff] [blame] | 151 | } |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 152 | } |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 153 | |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 154 | // @ts-expect-error https://github.com/GoogleChrome/lighthouse/issues/11628 |
| 155 | export class LighthouseReportUIFeatures extends LighthouseReport.ReportUIFeatures { |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 156 | private beforePrint: (() => void)|null; |
| 157 | private afterPrint: (() => void)|null; |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 158 | |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 159 | constructor(dom: LighthouseReport.DOM) { |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 160 | super(dom); |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 161 | this.beforePrint = null; |
| 162 | this.afterPrint = null; |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 165 | setBeforePrint(beforePrint: (() => void)|null): void { |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 166 | this.beforePrint = beforePrint; |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 169 | setAfterPrint(afterPrint: (() => void)|null): void { |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 170 | this.afterPrint = afterPrint; |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 174 | * Returns the html that recreates this report. |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 175 | */ |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 176 | getReportHtml(): string { |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 177 | this.resetUIState(); |
Connor Clark | 4a7d834 | 2021-07-19 13:38:37 -0700 | [diff] [blame] | 178 | // @ts-expect-error https://github.com/GoogleChrome/lighthouse/issues/11628 |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 179 | return Lighthouse.ReportGenerator.generateReportHtml(this.json); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Downloads a file (blob) using the system dialog prompt. |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 184 | */ |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 185 | // This implements the interface ReportUIFeatures from lighthouse |
| 186 | // which follows a different naming convention. |
| 187 | // eslint-disable-next-line rulesdir/no_underscored_properties, @typescript-eslint/naming-convention |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 188 | async _saveFile(blob: Blob|File): Promise<void> { |
Paul Lewis | daac106 | 2020-03-05 14:37:10 +0000 | [diff] [blame] | 189 | const domain = new Common.ParsedURL.ParsedURL(this.json.finalUrl).domain(); |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 190 | const sanitizedDomain = domain.replace(/[^a-z0-9.-]+/gi, '_'); |
Simon Zünd | 2c704cd | 2020-06-04 11:08:35 +0200 | [diff] [blame] | 191 | const timestamp = Platform.DateUtilities.toISO8601Compact(new Date(this.json.fetchTime)); |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 192 | const ext = blob.type.match('json') ? '.json' : '.html'; |
| 193 | const basename = `${sanitizedDomain}-${timestamp}${ext}`; |
| 194 | const text = await blob.text(); |
Tim van der Lippe | 696c926 | 2020-08-26 15:39:32 +0100 | [diff] [blame] | 195 | Workspace.FileManager.FileManager.instance().save(basename, text, true /* forceSaveAs */); |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 198 | // This implements the interface ReportUIFeatures from lighthouse |
| 199 | // which follows a different naming convention. |
| 200 | // eslint-disable-next-line rulesdir/no_underscored_properties, @typescript-eslint/naming-convention |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 201 | async _print(): Promise<void> { |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 202 | const document = this.getDocument(); |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 203 | const clonedReport = (document.querySelector('.lh-root') as HTMLElement).cloneNode(true); |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 204 | const printWindow = window.open('', '_blank', 'channelmode=1,status=1,resizable=1'); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 205 | if (!printWindow) { |
| 206 | return; |
| 207 | } |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 208 | const style = printWindow.document.createElement('style'); |
Tim van der Lippe | fe3cdc9 | 2020-11-06 15:23:13 +0000 | [diff] [blame] | 209 | style.textContent = Root.Runtime.cachedResources.get('third_party/lighthouse/report-assets/report.css') || ''; |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 210 | printWindow.document.head.appendChild(style); |
| 211 | printWindow.document.body.replaceWith(clonedReport); |
| 212 | // Linkified nodes are shadow elements, which aren't exposed via `cloneNode`. |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 213 | await LighthouseReportRenderer.linkifyNodeDetails(clonedReport as HTMLElement); |
Connor Clark | 9950836 | 2019-08-20 19:52:23 +0000 | [diff] [blame] | 214 | |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 215 | if (this.beforePrint) { |
| 216 | this.beforePrint(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 217 | } |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 218 | printWindow.focus(); |
| 219 | printWindow.print(); |
| 220 | printWindow.close(); |
Jan Scheffler | 9d4136d | 2021-08-10 12:55:04 +0200 | [diff] [blame^] | 221 | if (this.afterPrint) { |
| 222 | this.afterPrint(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 223 | } |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 226 | getDocument(): Document { |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 227 | return this._document; |
| 228 | } |
Jan Scheffler | c5a400f | 2021-01-22 17:41:47 +0100 | [diff] [blame] | 229 | resetUIState(): void { |
cjamcl@google.com | c5214af | 2019-06-25 20:31:21 +0000 | [diff] [blame] | 230 | this._resetUIState(); |
| 231 | } |
Paul Lewis | cf2ef22 | 2019-11-22 14:55:35 +0000 | [diff] [blame] | 232 | } |