From cf97646e6932f96a492b69411e4c82089bf76ff0 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Wed, 16 May 2018 13:26:39 -0700 Subject: [PATCH] revert fanciness introduced in #5204 --- .../report/html/renderer/report-ui-features.js | 10 +--------- lighthouse-viewer/app/src/lighthouse-report-viewer.js | 3 ++- lighthouse-viewer/app/src/viewer-ui-features.js | 7 +++++++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lighthouse-core/report/html/renderer/report-ui-features.js b/lighthouse-core/report/html/renderer/report-ui-features.js index 14ffbd3355bf..a1757ca70632 100644 --- a/lighthouse-core/report/html/renderer/report-ui-features.js +++ b/lighthouse-core/report/html/renderer/report-ui-features.js @@ -353,25 +353,19 @@ 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); } }); @@ -379,8 +373,6 @@ class ReportUIFeatures { 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; } /** diff --git a/lighthouse-viewer/app/src/lighthouse-report-viewer.js b/lighthouse-viewer/app/src/lighthouse-report-viewer.js index a67246456833..0dac51d60938 100644 --- a/lighthouse-viewer/app/src/lighthouse-report-viewer.js +++ b/lighthouse-viewer/app/src/lighthouse-report-viewer.js @@ -175,7 +175,7 @@ class LighthouseReportViewer { } /** - * Opens new tab with compatible report viewer version + * Opens legacy viewer in current tab, then renders report * @param {!ReportRenderer.ReportJSON} reportJson * @private */ @@ -183,6 +183,7 @@ class LighthouseReportViewer { 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; diff --git a/lighthouse-viewer/app/src/viewer-ui-features.js b/lighthouse-viewer/app/src/viewer-ui-features.js index e213bf358d32..8d880b157d2a 100644 --- a/lighthouse-viewer/app/src/viewer-ui-features.js +++ b/lighthouse-viewer/app/src/viewer-ui-features.js @@ -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 */