Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: add onViewTrace to renderer options #13528

Merged
merged 7 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8729,6 +8729,8 @@
"throttlingProvided": "Provided by environment",
"toplevelWarningsMessage": "There were issues affecting this run of Lighthouse:",
"varianceDisclaimer": "Values are estimated and may vary. The [performance score is calculated](https://web.dev/performance-scoring/) directly from these metrics.",
"viewOriginalTraceLabel": "View Original Trace",
"viewTraceLabel": "View Trace",
"viewTreemapLabel": "View Treemap",
"warningAuditsGroupTitle": "Passed audits but with warnings",
"warningHeader": "Warnings: "
Expand Down
4 changes: 4 additions & 0 deletions lighthouse-core/util-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ const UIStrings = {
thirdPartyResourcesLabel: 'Show 3rd-party resources',
/** This label is for a button that opens a new tab to a webapp called "Treemap", which is a nested visual representation of a heierarchy of data related to the reports (script bytes and coverage, resource breakdown, etc.) */
viewTreemapLabel: 'View Treemap',
/** This label is for a button that will show the user a trace of the page. */
viewTraceLabel: 'View Trace',
/** This label is for a button that will show the user a trace of the page. */
viewOriginalTraceLabel: 'View Original Trace',

/** Option in a dropdown menu that opens a small, summary report in a print dialog. */
dropdownPrintSummary: 'Print Summary',
Expand Down
6 changes: 6 additions & 0 deletions proto/lighthouse-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ message I18n {

// Label indicating that Lighthouse throttled the page using custom throttling settings.
string runtime_custom = 57;

// This label is for a button that will show the user a trace of the page.
string view_trace_label = 58;

// This label is for a button that will show the user a trace of the page.
string view_original_trace_label = 59;
}

// The message holding all formatted strings used in the renderer.
Expand Down
9 changes: 9 additions & 0 deletions report/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ export class ReportUIFeatures {
});
}

if (this._opts.onViewTrace) {
this.addButton({
text: lhr.configSettings.throttlingMethod === 'simulate' ?
Util.i18n.strings.viewOriginalTraceLabel :
Util.i18n.strings.viewTraceLabel,
onClick: () => this._opts.onViewTrace?.(),
});
}

if (this._opts.getStandaloneReportHTML) {
this._dom.find('a[data-action="save-html"]', this._dom.rootEl).classList.remove('lh-hidden');
}
Expand Down
4 changes: 4 additions & 0 deletions report/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ const UIStrings = {
thirdPartyResourcesLabel: 'Show 3rd-party resources',
/** This label is for a button that opens a new tab to a webapp called "Treemap", which is a nested visual representation of a heierarchy of data related to the reports (script bytes and coverage, resource breakdown, etc.) */
viewTreemapLabel: 'View Treemap',
/** This label is for a button that will show the user a trace of the page. */
viewTraceLabel: 'View Trace',
/** This label is for a button that will show the user a trace of the page. */
viewOriginalTraceLabel: 'View Original Trace',

/** Option in a dropdown menu that opens a small, summary report in a print dialog. */
dropdownPrintSummary: 'Print Summary',
Expand Down
7 changes: 7 additions & 0 deletions report/types/report-renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { Result as AuditResult } from "../../types/lhr/audit-result";
import { ReportUIFeatures } from "../renderer/report-ui-features.js";

declare module Renderer {
function renderReport(lhr: AuditResult, options?: Options): HTMLElement;
Expand All @@ -26,6 +27,12 @@ declare module Renderer {
onPageAnchorRendered?: (link: HTMLAnchorElement) => void;
/** If defined, `Save as HTML` option is shown in dropdown menu. */
getStandaloneReportHTML?: () => string;
/**
* If defined, adds a `View Trace` button to the report, and calls this callback when clicked.
* The callback should do something to present the user with a visualization of the trace
* data, which can be gotten from the artifacts.
*/
onViewTrace?: () => void;
}
}

Expand Down
6 changes: 6 additions & 0 deletions shared/localization/locales/en-US.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions shared/localization/locales/en-XL.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.