Skip to content

Commit

Permalink
core(artifacts): expose id attribute for ScriptElements (#9718)
Browse files Browse the repository at this point in the history
  • Loading branch information
uchoudh-zz authored and brendankenny committed Sep 27, 2019
1 parent 6fe75fb commit 6dde98c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
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
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+$/,
url: 'http://localhost:10200/dobetterweb/dbw_tester.html',
},
],
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/gather/gatherers/script-elements.js
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
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
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

0 comments on commit 6dde98c

Please sign in to comment.