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

core(scriptelements): expose id attribute for ScriptElements #9718

Merged
merged 5 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- AMP-style stylesheet script -->
<!-- based on https://github.com/ampproject/amphtml/blob/38f1bdf4cc385f9a25cf2979abf215952880b876/src/font-stylesheet-timeout.js#L87-L103 -->
<script type="text/javascript">
<script type="text/javascript" id="amp-style-styling-script">
setTimeout(() => {
const stylesheet = document.getElementById('amp-style-link');
stylesheet.media = 'not-matching';
Expand Down Expand Up @@ -48,13 +48,13 @@
<link rel="alternate stylesheet" href="./empty.css">

<!-- FAIL: block rendering -->
<script src="./dbw_tester.js"></script>
<script src="./dbw_tester.js" id="dbw-tester-script"></script>

<!-- PASS: 'modules' are deferred by default and don't block rendering -->
<script type="module" src="./empty_module.js?delay=500"></script>

<!-- FAIL(errors-in-console): exception thrown -->
<script type="text/javascript">throw new Error('An error');</script>
<script type="text/javascript" id="error-time">throw new Error('A distinctive error');</script>

<!-- Add non-functional script to appear to be a Wordpress page for Stack Packs. -->
<script type="example" src="fake-script-wp-includes"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = [
},
{
source: 'Runtime.exception',
description: 'Error: An error\n at http://localhost:10200/dobetterweb/dbw_tester.html:57:38',
description: /^Error: A distinctive error\s+at http:\/\/localhost:10200\/dobetterweb\/dbw_tester.html:\d+:\d+$/,
Copy link
Member

Choose a reason for hiding this comment

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

another annoying failure for new contributors :) Made the smoke test expectation less sensitive because we don't need to verify the exact column number

url: 'http://localhost:10200/dobetterweb/dbw_tester.html',
},
],
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/gather/gatherers/script-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function collectAllScriptElements() {
return {
type: script.type || null,
src: script.src || null,
id: script.id || null,
async: script.async,
defer: script.defer,
source: /** @type {'head'|'body'} */ (script.closest('head') ? 'head' : 'body'),
Expand Down Expand Up @@ -81,6 +82,7 @@ class ScriptElements extends Gatherer {
devtoolsNodePath: '',
type: null,
src: record.url,
id: null,
async: false,
defer: false,
source: 'network',
Expand Down
10 changes: 10 additions & 0 deletions lighthouse-core/test/results/artifacts/artifacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
{
"type": "text/javascript",
"src": null,
"id": "amp-style-styling-script",
"async": false,
"defer": false,
"source": "head",
Expand All @@ -253,6 +254,7 @@
{
"type": null,
"src": "http://localhost:10200/dobetterweb/dbw_tester.js",
"id": "dbw-tester-script",
"async": false,
"defer": false,
"source": "head",
Expand All @@ -263,6 +265,7 @@
{
"type": "module",
"src": "http://localhost:10200/dobetterweb/empty_module.js?delay=500",
"id": null,
"async": false,
"defer": false,
"source": "head",
Expand All @@ -273,6 +276,7 @@
{
"type": "text/javascript",
"src": null,
"id": "error-time",
"async": false,
"defer": false,
"source": "head",
Expand All @@ -283,6 +287,7 @@
{
"type": null,
"src": "http://localhost:10200/dobetterweb/fcp-delayer.js?delay=5000",
"id": null,
"async": false,
"defer": false,
"source": "head",
Expand All @@ -293,6 +298,7 @@
{
"type": null,
"src": null,
"id": null,
"async": false,
"defer": false,
"source": "body",
Expand All @@ -303,6 +309,7 @@
{
"type": null,
"src": null,
"id": null,
"async": false,
"defer": false,
"source": "body",
Expand All @@ -313,6 +320,7 @@
{
"type": null,
"src": null,
"id": null,
"async": false,
"defer": false,
"source": "body",
Expand All @@ -323,6 +331,7 @@
{
"type": null,
"src": "http://localhost:10200/zone.js",
"id": null,
"async": false,
"defer": false,
"source": "body",
Expand All @@ -333,6 +342,7 @@
{
"type": null,
"src": "http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js",
"id": null,
"async": false,
"defer": false,
"source": "body",
Expand Down
2 changes: 2 additions & 0 deletions types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ declare global {
export interface ScriptElement {
type: string | null
src: string | null
/** The `id` property of the script element; null if it had no `id` or if `source` is 'network'. */
id: string | null
async: boolean
defer: boolean
/** Path that uniquely identifies the node in the DOM */
Expand Down