Skip to content

Commit

Permalink
revert fanciness introduced in #5204
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed May 16, 2018
1 parent 5881613 commit cf97646
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 1 addition & 9 deletions lighthouse-core/report/html/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,34 +353,26 @@ class ReportUIFeatures {
* @protected
*/
static openTabAndSendJsonReport(reportJson, viewerPath) {
let resolve;
const p = new Promise(res => resolve = res);
// Chrome doesn't allow us to immediately postMessage to a popup right
// after it's created. Normally, we could also listen for the popup window's
// load event, however it is cross-domain and won't fire. Instead, listen
// for a message from the target app saying "I'm open".
const json = reportJson;
window.addEventListener('message', function msgHandler(/** @type {!Event} */ e) {
const messageEvent = /** @type {!MessageEvent<{opened: boolean, rendered: boolean}>} */ (e);
const messageEvent = /** @type {!MessageEvent<{opened: boolean}>} */ (e);
if (messageEvent.origin !== VIEWER_ORIGIN) {
return;
}
// Most recent deployment
if (messageEvent.data.opened) {
popup.postMessage({lhresults: json}, VIEWER_ORIGIN);
}
if (messageEvent.data.rendered) {
window.removeEventListener('message', msgHandler);
resolve(popup);
}
});

// The popup's window.name is keyed by version+url+fetchTime, so we reuse/select tabs correctly
const fetchTime = json.fetchTime || json.generatedTime;
const windowName = `${json.lighthouseVersion}-${json.requestedUrl}-${fetchTime}`;
const popup = /** @type {!Window} */ (window.open(`${VIEWER_ORIGIN}${viewerPath}`, windowName));

return p;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-viewer/app/src/lighthouse-report-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ class LighthouseReportViewer {
}

/**
* Opens new tab with compatible report viewer version
* Opens legacy viewer in current tab, then renders report
* @param {!ReportRenderer.ReportJSON} reportJson
* @private
*/
_loadInLegacyViewerVersion(json) {
const warnMsg = `Version mismatch between viewer and JSON. Opening compatible viewer...`;
logger.log(warnMsg, false);

// Place report in IDB, then navigate current tab to the legacy viewer
const viewerPath = new URL('../viewer2x/', location.href);
idbKeyval.set('2xreport', json).then(_ => {
window.location.href = viewerPath;
Expand Down
7 changes: 7 additions & 0 deletions lighthouse-viewer/app/src/viewer-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class ViewerUIFeatures extends ReportUIFeatures {
return ReportGenerator.generateReportHtml(this.json);
}

/**
* @override
*/
sendJsonReport() {
throw new Error('Cannot send JSON to Viewer from Viewer.');
}

/**
* @override
*/
Expand Down

0 comments on commit cf97646

Please sign in to comment.