-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc(viewer): support 3.x and legacy (2.x) reports in viewer #5204
Changes from 4 commits
4f3016b
f98f218
6166fb5
4e8bd18
79446e3
5cf1d57
9f1762e
b50639d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,11 @@ class LighthouseReportViewer { | |
_replaceReportHtml(json) { | ||
this._validateReportJson(json); | ||
|
||
if (!json.lighthouseVersion.startsWith('3')) { | ||
this._loadInLegacyViewerVersion(json); | ||
return; | ||
} | ||
|
||
const dom = new DOM(document); | ||
const renderer = new ReportRenderer(dom); | ||
|
||
|
@@ -164,12 +169,30 @@ class LighthouseReportViewer { | |
} catch (e) { | ||
throw new Error('Could not parse JSON file.'); | ||
} | ||
|
||
this._reportIsFromGist = false; | ||
this._replaceReportHtml(json); | ||
}).catch(err => logger.error(err.message)); | ||
} | ||
|
||
/** | ||
* Opens new tab with compatible report viewer version | ||
* @param {!ReportRenderer.ReportJSON} reportJson | ||
* @private | ||
*/ | ||
_loadInLegacyViewerVersion(json) { | ||
const warnMsg = `Version mismatch between viewer and JSON. | ||
Opening new tab with compatible viewer.`; | ||
const features = new ViewerUIFeatures(new DOM(document)); | ||
const viewerPath = '/lighthouse/viewer2x/'; | ||
|
||
logger.log(warnMsg, false); | ||
features.sendJsonReport(json, viewerPath, onMessage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. impl is a bit confusing that we create a temporary instance of the ViewerUIfeatures to trigger the render in viewer, feels a bit hacky I think it's mostly just the fake flexibility of they could just resolve a promise when they get confirmation that the report has been rendered and nix the onMessage piece |
||
function onMessage(data) { | ||
if (data.rendered) window.close(); | ||
logger.log(`${warnMsg} You can close this tab.`, false); | ||
} | ||
} | ||
|
||
/** | ||
* Reads a file and returns its content as a string. | ||
* @param {!File} file | ||
|
@@ -296,6 +319,10 @@ class LighthouseReportViewer { | |
if (e.source === self.opener && e.data.lhresults) { | ||
this._reportIsFromGist = false; | ||
this._replaceReportHtml(e.data.lhresults); | ||
|
||
if (self.opener && !self.opener.closed) { | ||
self.opener.postMessage({rendered: true}, '*'); | ||
} | ||
if (window.ga) { | ||
window.ga('send', 'event', 'report', 'open in viewer'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because we need to listen for the render message to close? will this cause duplicate handler problems if they click "Open in viewer" twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question. @ebidel is that the situation this is handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember one issue is if you open viewer from a report, then use viewer as a viewer (looking at other reports or something), if you refresh it will send back an
opened
message back to the original report and load the first report, not whatever you've been doing since.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what @brendankenny described is the sitch. Although I'm not sure why Chrome does that, but you sometimes get another
message
event when the page refreshes.