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

Only count scripts for duplicate tag loading #172

Merged
merged 2 commits into from
Dec 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lighthouse-plugin-publisher-ads/audits/duplicate-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n');
const NetworkRecords = require('lighthouse/lighthouse-core/computed/network-records');
const NetworkRequest = require('lighthouse/lighthouse-core/lib/network-request');
const {auditNotApplicable} = require('../messages/common-strings');
const {Audit} = require('lighthouse');
const {containsAnySubstring} = require('../utils/resource-classification');
Expand Down Expand Up @@ -78,7 +79,8 @@ class DuplicateTags extends Audit {
const devtoolsLogs = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const networkRecords = await NetworkRecords.request(devtoolsLogs, context);
const tagReqs = networkRecords
.filter((record) => containsAnySubstring(record.url, tags));
.filter((r) => containsAnySubstring(r.url, tags))
.filter((r) => (r.resourceType === NetworkRequest.TYPES.Script));

if (!tagReqs.length) {
return auditNotApplicable.NoTags;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';

/**
* Expected Lighthouse audit values for perf tests.
*/
module.exports = [
{
lhr: {
requestedUrl: 'http://localhost:8081/duplicate-tags.html',
finalUrl: 'http://localhost:8081/duplicate-tags.html',
audits: {
'duplicate-tags': {
score: 0,
details: {
items: [
{
script: '/tag/js/gpt.js',
numReqs: 2, // Two script reqs, ignore third prefetch request
},
],
},
},
},
},
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<!--
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Duplicate tags</title>
<style>
p {
font-size: 50px;
}
</style>
<script>googletag = window.googletag || {cmd: []};</script>
<link rel=prefetch as=script href="https://securepubads.g.doubleclick.net/tag/js/gpt.js"/>
<script defer src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script async src="./slowly-inject-gpt.js"></script>
<script>
googletag.cmd.push(() => {
googletag.defineSlot('/6355419/Travel', [728, 90], `ad`)
.setTargeting("test","infinitescroll")
.addService(googletag.pubads());
});
googletag.cmd.push(function() {
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
<body>
<div id="ad" style="width: 728px; height: 90px; position: fixed;">
<script>
googletag.cmd.push(function() { googletag.display('ad'); });
</script>
</div>

<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pretium justo
enim. Vivamus non congue ligula, non pulvinar risus. Ut sodales pulvinar
sem, et semper mi fringilla quis. Donec ac lacus orci. Sed pharetra eros
et risus egestas fermentum. Cras pulvinar metus tempus, varius nunc ut,
ullamcorper massa. Nam tempus imperdiet molestie. Mauris et bibendum
lorem. Nunc metus leo, rhoncus quis mollis nec, ultricies a erat.
Suspendisse sed auctor mauris, sit amet faucibus neque. Praesent commodo
tortor et lorem imperdiet, ac interdum massa molestie. Aliquam in
bibendum sem. Duis bibendum ex dolor, et molestie sem aliquam non. Duis
eu risus nec lectus maximus imperdiet. In mi velit, varius sit amet enim
a, semper tristique sapien. Nulla in leo sed nibh dictum pharetra rhoncus
id lacus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pretium justo
enim. Vivamus non congue ligula, non pulvinar risus. Ut sodales pulvinar
sem, et semper mi fringilla quis. Donec ac lacus orci. Sed pharetra eros
et risus egestas fermentum. Cras pulvinar metus tempus, varius nunc ut,
ullamcorper massa. Nam tempus imperdiet molestie. Mauris et bibendum
lorem. Nunc metus leo, rhoncus quis mollis nec, ultricies a erat.
Suspendisse sed auctor mauris, sit amet faucibus neque. Praesent commodo
tortor et lorem imperdiet, ac interdum massa molestie. Aliquam in
bibendum sem. Duis bibendum ex dolor, et molestie sem aliquam non. Duis
eu risus nec lectus maximus imperdiet. In mi velit, varius sit amet enim
a, semper tristique sapien. Nulla in leo sed nibh dictum pharetra rhoncus
id lacus.
</p>

</body>
</html>
6 changes: 6 additions & 0 deletions lighthouse-plugin-publisher-ads/test/smoke/smoke-test-dfns.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

/** @type {Array<Smokehouse.TestDfn>} */
const smokeTests = [
{
id: 'duplicate-tags',
expectations: require('./expectations/duplicate-tags.js'),
config: require('./config.js'),
batch: 'pub-ads',
},
{
id: 'lazy-load',
expectations: require('./expectations/lazy-load.js'),
Expand Down