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

misc(viewer): accept lhr from fragment #12557

Merged
merged 31 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d5123ca
report: encode data even if very large
connorjclark May 19, 2021
267d578
ok
connorjclark May 19, 2021
d7281c0
rm
connorjclark May 20, 2021
ff0bfd1
no btoa lol
connorjclark May 20, 2021
c417fcb
benchmark
connorjclark May 20, 2021
8ac3a39
lol
connorjclark May 20, 2021
720c427
test
connorjclark May 20, 2021
f0e8949
pako
connorjclark May 20, 2021
6d6e453
fixtest
connorjclark May 20, 2021
ef3e69e
test
connorjclark May 20, 2021
c9c60df
minify
connorjclark May 20, 2021
585bfa0
Merge remote-tracking branch 'origin/master' into treemap-encode
connorjclark May 20, 2021
a638270
tweak
connorjclark May 20, 2021
9eb78f6
dont use minified
connorjclark May 20, 2021
d985f61
gzip optional
connorjclark May 20, 2021
13a4671
upgrade puppeteer for compression stream
connorjclark May 20, 2021
07e3c8d
revert puppeteer upgrade
connorjclark May 21, 2021
ea226a6
Merge remote-tracking branch 'origin/master' into treemap-encode
connorjclark May 21, 2021
5365e53
update
connorjclark May 21, 2021
a6ff9bb
yay
connorjclark May 21, 2021
b473636
pr
connorjclark May 21, 2021
50ff2f1
names
connorjclark May 24, 2021
ca16fff
deprecate postmessage
connorjclark May 24, 2021
34a67e3
misc(viewer): accept lhr from fragment
connorjclark May 25, 2021
c588523
Merge remote-tracking branch 'origin/master' into viewer-encode
paulirish Jun 10, 2021
023c989
resolve remaining merge issues
paulirish Jun 10, 2021
a2ebd0c
update
connorjclark Jun 21, 2021
2fc69d1
add log if decode failed
paulirish Jun 28, 2021
7c78153
Merge remote-tracking branch 'origin/master' into viewer-encode
connorjclark Jul 23, 2021
77afee6
Merge branch 'viewer-encode' of github.com:GoogleChrome/lighthouse in…
connorjclark Jul 23, 2021
3fd3591
fix
connorjclark Jul 23, 2021
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
1 change: 1 addition & 0 deletions build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function run() {
javascripts: [
await generatorJsPromise,
fs.readFileSync(require.resolve('idb-keyval/dist/idb-keyval-min.js'), 'utf8'),
fs.readFileSync(require.resolve('pako/dist/pako_inflate.js'), 'utf-8'),
{path: '../../dist/report/viewer.js'},
{path: 'src/*'},
],
Expand Down
13 changes: 12 additions & 1 deletion lighthouse-viewer/app/src/lighthouse-report-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

/* global DOM, ViewerUIFeatures, ReportRenderer, DragAndDrop, GithubApi, PSIApi, logger, idbKeyval */
/* global DOM, ViewerUIFeatures, ReportRenderer, DragAndDrop, GithubApi, PSIApi, logger, idbKeyval, TextEncoding */

/** @typedef {import('./psi-api').PSIParams} PSIParams */

Expand Down Expand Up @@ -103,6 +103,17 @@ class LighthouseReportViewer {
const gistId = params.get('gist');
const psiurl = params.get('psiurl');
const jsonurl = params.get('jsonurl');
const gzip = params.get('gzip') === '1';

if (location.hash) {
const hashParams = JSON.parse(TextEncoding.fromBase64(location.hash.substr(1), {gzip}));
if (hashParams.lhr) {
this._replaceReportHtml(hashParams.lhr);
return Promise.resolve();
} else {
console.warn('URL hash is populated, but not decoded successfully', hashParams);
}
}

if (!gistId && !psiurl && !jsonurl) return Promise.resolve();

Expand Down
2 changes: 2 additions & 0 deletions lighthouse-viewer/types/viewer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {DOM as _DOM} from '../../report/renderer/dom.js';
import {ReportRenderer as _ReportRenderer} from '../../report/renderer/report-renderer.js';
import {ReportUIFeatures as _ReportUIFeatures} from '../../report/renderer/report-ui-features.js';
import {Logger as _Logger} from '../../report/renderer/logger.js';
import {TextEncoding as _TextEncoding} from '../../report/renderer/text-encoding.js';
import {getFilenamePrefix as _getFilenamePrefix} from '../../report/renderer/file-namer.js';
import _LighthouseReportViewer = require('../app/src/lighthouse-report-viewer.js');
import _DragAndDrop = require('../app/src/drag-and-drop.js');
Expand All @@ -27,6 +28,7 @@ declare global {
var ReportRenderer: typeof _ReportRenderer;
var ReportUIFeatures: typeof _ReportUIFeatures;
var Logger: typeof _Logger;
var TextEncoding: typeof _TextEncoding;
var logger: _Logger;
var getFilenamePrefix: typeof _getFilenamePrefix;
var LighthouseReportViewer: typeof _LighthouseReportViewer;
Expand Down
2 changes: 2 additions & 0 deletions report/clients/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {DOM} from '../renderer/dom.js';
import {Logger} from '../renderer/logger.js';
import {ReportRenderer} from '../renderer/report-renderer.js';
import {ReportUIFeatures} from '../renderer/report-ui-features.js';
import {TextEncoding} from '../renderer/text-encoding.js';

window.DOM = DOM;
window.Logger = Logger;
window.ReportRenderer = ReportRenderer;
window.ReportUIFeatures = ReportUIFeatures;
window.TextEncoding = TextEncoding;
16 changes: 12 additions & 4 deletions report/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,15 @@ export class ReportUIFeatures {
break;
}
case 'open-viewer': {
ReportUIFeatures.openTabAndSendJsonReportToViewer(this.json);
// DevTools cannot send data with postMessage, and we only want to use the URL fragment
// approach for viewer when needed, so check the environment and choose accordingly.
if (this._dom.isDevTools()) {
ReportUIFeatures.openViewer(this.json);
} else {
const windowName = 'viewer-' + ReportUIFeatures.computeWindowNameSuffix(this.json);
const url = getAppsOrigin() + '/viewer/';
ReportUIFeatures.openTabWithUrlData({lhr: this.json}, url, windowName);
}
break;
}
case 'save-gist': {
Expand Down Expand Up @@ -550,14 +558,14 @@ export class ReportUIFeatures {

/**
* Opens a new tab to the online viewer and sends the local page's JSON results
* to the online viewer using postMessage.
* to the online viewer using URL.fragment
* @param {LH.Result} json
* @protected
*/
static openTabAndSendJsonReportToViewer(json) {
static openViewer(json) {
const windowName = 'viewer-' + this.computeWindowNameSuffix(json);
const url = getAppsOrigin() + '/viewer/';
ReportUIFeatures.openTabAndSendData({lhr: json}, url, windowName);
ReportUIFeatures.openTabWithUrlData({lhr: json}, url, windowName);
}

/**
Expand Down