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

don't emit script tags in devtools report. #1105

Merged
merged 2 commits into from
Dec 13, 2016
Merged

Conversation

paulirish
Copy link
Member

Our devtools integration is that the report is hosted in and iframe (with a blob url).

DevTools has a CSP policy: https://github.com/ChromeDevTools/devtools-frontend/blob/master/front_end/inspector.html#L10
It prevents inline scripts from running.

That ends up throwing an error for our report. While there may be some ways to handle this at a CSP layer, I'd prefer, in the short term, to make our report function without javascript.

The report only needs JS for the window.print() which is hidden from the devtools version (via reportContext).

This PR tweaks things so we don't ship a script tag to devtools; and we only ship 1 script tag to the extension.

</head>
<body>

<script>
// expose the original results
<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we just remove? The JSON embed makes the html report reallllly big.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like it's useful to keep around, but I don't have the strongest usecase just yet.

e.g. what if a report-viewer customer wants to d/l the JSON from a report they are looking at, so they can archive it and compare past results?

but.. I'm OK with nuking it for now and only bringing it back when there's definite need.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We'll need the JSON embedded for that use case. We can add it back later :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k will do.

@@ -173,7 +173,8 @@ class ReportGenerator {
* @return {string}
*/
getReportJS() {
return fs.readFileSync(path.join(__dirname, './scripts/lighthouse-report.js'), 'utf8');
const scriptSrc = fs.readFileSync(path.join(__dirname, './scripts/lighthouse-report.js'), 'utf8');
return `<script>${scriptSrc}</script>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep getReportJS() the same and use handlebars to conditionally write them if there's a script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. sg.

@@ -261,14 +262,16 @@ class ReportGenerator {
});

const template = Handlebars.compile(this.getReportTemplate());
reportContext = reportContext || 'extension'; // could be: devtools, extension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesn't it have reportContext for the extension at this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should, but I can imagine someone using generateHTML on their own, and not setting the second argument.
would you rather this go forward as undefined or we throw?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that's fine (and I just noticed you were just moving it up from where it already was). Maybe just add a note about the default to the jsdoc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it appears this is just used for styling, and just for devtools embed right now. I wonder if we should rename it to something to indicate that. reportStyle or whatever

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(maybe reportContext means that already, but without context I was thinking it was more "what generated this report" rather than "what's managing the viewer for this report")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k. added more detail to jsDoc and moved the default value to top of function. this work for you?

I could also rename to reportStyle if you prefer, works for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also rename to reportStyle if you prefer, works for me.

as I read it today reportContext makes perfect sense, so who knows :)

@paulirish
Copy link
Member Author

ptal

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the tests (that are taking forever to run), report-test.js still has a line (52) that's too long, and the first assertion fails in generates extension HTML due to that test file being really out of date. We haven't used {inline: true} in a while

@brendankenny
Copy link
Member

you should rebase. Eric removed those {inline: true} lines in #1117, which should help

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from me after you rebase off master. That should fix the test issues.

@paulirish
Copy link
Member Author

rebased and all that jazz @brendankenny

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis is useless but local tests and CLI and extension work and look good

@brendankenny brendankenny merged commit a17fa72 into master Dec 13, 2016
@brendankenny brendankenny deleted the scripttagsno branch December 13, 2016 21:30
andrewrota pushed a commit to andrewrota/lighthouse that referenced this pull request Jan 13, 2017
* don't emit script tags in devtools report.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants