Skip to content

Commit 561efc2

Browse files
committed
Added audit configurations to extension
1 parent 6663f6b commit 561efc2

File tree

4 files changed

+126
-16
lines changed

4 files changed

+126
-16
lines changed

lighthouse-extension/app/popup.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,36 @@ <h2 class="header-titles__url">...</h2>
3838

3939
<main class="main" role="main">
4040
<div class="feedback"></div>
41-
<button class="generate-report">Generate report</button>
41+
42+
<button class="button button--link button--configure" id="configure-options">Options</button>
43+
<button class="button button--generate" id="generate-report">Generate report</button>
4244
</main>
4345

44-
<aside class="status">
46+
<aside class="status subpage">
4547
<div class="status__spinner"></div>
4648
<div class="status__msg">Starting...</div>
4749
<div><small class="status__detailsmsg"></small></div>
4850
</aside>
4951

52+
<aside class="options subpage">
53+
<h2 class="options__title">Options</h2>
54+
<ul class="options__list">
55+
<li><input type="checkbox" id="offline" checked="checked" value="App can load on offline/flaky connections" /><label for="offline">App can load on offline/flaky connections</label></li>
56+
<li><input type="checkbox" id="pageload" checked="checked" value="Page load performance is fast" /><label for="pageload">Page load performance</label></li>
57+
<li><input type="checkbox" id="progressive" checked="checked" value="Site is progressively enhanced" /><label for="progressive">Site is progressively enhanced</label></li>
58+
<li><input type="checkbox" id="secure" checked="checked" value="Network connection is secure" /><label for="secure">Network connection is secure</label></li>
59+
<li><input type="checkbox" id="homescreen" checked="checked" value="User can be prompted to Add to Homescreen" /><label for="homescreen">User can be prompted to Add to Homescreen</label></li>
60+
<li><input type="checkbox" id="splashscreen" checked="checked" value="Installed web app will launch with custom splash screen" /><label for="splashscreen">Installed web app will launch with custom splash screen</label></li>
61+
<li><input type="checkbox" id="brandcolor" checked="checked" value="Address bar matches brand colors" /><label for="brandcolor">Address bar matches brand colors</label></li>
62+
<li><input type="checkbox" id="mobile-friendly" checked="checked" value="Design is mobile-friendly" /><label for="mobile-friendly">Design is mobile-friendly</label></li>
63+
<li>&nbsp;</li>
64+
<li><input type="checkbox" id="bestpractices" checked="checked" value="Best Practices" /><label for="bestpractices">Best Practices</label></li>
65+
<li><input type="checkbox" id="performance" checked="checked" value="Performance Metrics" /><label for="performance">Performance Metrics</label></li>
66+
</ul>
67+
68+
<button class="button button--link button--go-back" id="go-back">Back</button>
69+
</aside>
70+
5071
<script src="scripts/popup.js"></script>
5172
</body>
5273
</html>

lighthouse-extension/app/src/lighthouse-background.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ window.createPageAndPopulate = function(results) {
3737
});
3838
};
3939

40-
window.runAudits = function(options) {
40+
window.runAudits = function(options, audits) {
4141
// Default to 'info' logging level.
4242
log.setLevel('info');
4343

4444
const driver = new ExtensionProtocol();
4545

4646
return driver.getCurrentTabURL()
4747
.then(url => {
48-
// Setup the run config, false == no whitelist, run all audits
49-
const config = new Config(configJSON, false);
48+
// Setup the run config, audits are calculated by selected options
49+
const config = new Config(configJSON, new Set(audits));
5050

5151
// Add in the URL to the options.
5252
return Runner.run(driver, Object.assign({}, options, {url, config}));

lighthouse-extension/app/src/popup.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,34 @@
1515
* limitations under the License.
1616
*/
1717

18+
const configJSON = require('../../../lighthouse-core/config/default.json');
19+
const _flatten = arr => [].concat.apply([], arr);
20+
const aggregations = _flatten([
21+
configJSON.aggregations[0].items,
22+
configJSON.aggregations[1],
23+
configJSON.aggregations[2]
24+
]);
25+
1826
document.addEventListener('DOMContentLoaded', _ => {
1927
const background = chrome.extension.getBackgroundPage();
2028
const siteNameEl = window.document.querySelector('header h2');
21-
const generateReportEl = document.body.querySelector('.generate-report');
29+
const generateReportEl = document.getElementById('generate-report');
30+
const subpageVisibleClass = 'subpage--visible';
2231

2332
const statusEl = document.body.querySelector('.status');
2433
const statusMessageEl = document.body.querySelector('.status__msg');
2534
const statusDetailsMessageEl = document.body.querySelector('.status__detailsmsg');
2635
const spinnerEl = document.body.querySelector('.status__spinner');
2736
const feedbackEl = document.body.querySelector('.feedback');
37+
38+
const generateOptionsEl = document.getElementById('configure-options');
39+
const optionsEl = document.body.querySelector('.options');
40+
const goBack = document.getElementById('go-back');
41+
2842
let spinnerAnimation;
2943

3044
const startSpinner = _ => {
31-
statusEl.classList.add('status--visible');
45+
statusEl.classList.add(subpageVisibleClass);
3246
spinnerAnimation = spinnerEl.animate([
3347
{transform: 'rotate(0deg)'},
3448
{transform: 'rotate(359deg)'}
@@ -40,25 +54,46 @@ document.addEventListener('DOMContentLoaded', _ => {
4054

4155
const stopSpinner = _ => {
4256
spinnerAnimation.cancel();
43-
statusEl.classList.remove('status--visible');
57+
statusEl.classList.remove(subpageVisibleClass);
4458
};
4559

4660
const logstatus = ([, message, details]) => {
4761
statusMessageEl.textContent = message;
4862
statusDetailsMessageEl.textContent = details;
4963
};
5064

65+
const getAuditsOfName = name => {
66+
let aggregation = aggregations.filter(aggregation => aggregation.name === name);
67+
68+
if (!aggregation.length) {
69+
return [];
70+
}
71+
72+
// This checks if we have a a criteria property, it's necessary to check categories like Best Practices
73+
if (!aggregation[0].hasOwnProperty('criteria')) {
74+
aggregation = aggregation[0].items;
75+
}
76+
77+
return Object.keys(aggregation[0].criteria);
78+
};
79+
5180
background.listenForStatus(logstatus);
5281

5382
generateReportEl.addEventListener('click', () => {
5483
startSpinner();
5584
feedbackEl.textContent = '';
85+
86+
const audits = _flatten(
87+
Array.from(optionsEl.querySelectorAll(':checked'))
88+
.map(input => getAuditsOfName(input.value))
89+
);
90+
5691
background.runAudits({
5792
flags: {
5893
mobile: true,
5994
loadPage: true
6095
}
61-
})
96+
}, audits)
6297
.then(results => {
6398
background.createPageAndPopulate(results);
6499
})
@@ -74,6 +109,14 @@ document.addEventListener('DOMContentLoaded', _ => {
74109
});
75110
});
76111

112+
generateOptionsEl.addEventListener('click', () => {
113+
optionsEl.classList.add(subpageVisibleClass);
114+
});
115+
116+
goBack.addEventListener('click', () => {
117+
optionsEl.classList.remove(subpageVisibleClass);
118+
});
119+
77120
chrome.tabs.query({active: true, lastFocusedWindow: true}, function(tabs) {
78121
if (tabs.length === 0) {
79122
return;

lighthouse-extension/app/styles/lighthouse.css

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,24 @@ body {
108108
border-top: 1px solid rgba(255,255,255,0.1);
109109
background: #49525F;
110110
justify-content: space-around;
111-
flex-direction: column;
111+
flex-direction: row;
112112
align-items: flex-end;
113113
}
114114

115-
.generate-report {
115+
.button {
116+
cursor: pointer;
117+
}
118+
119+
.button--link {
120+
background: none;
121+
border: none;
122+
box-shadow: none;
123+
color: #FFF;
124+
text-decoration: underline;
125+
cursor: pointer;
126+
}
127+
128+
.button--generate {
116129
font-family: 'Roboto', Arial, sans-serif;
117130
-webkit-font-smoothing: antialiased;
118131
font-weight: 500;
@@ -124,9 +137,23 @@ body {
124137
box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.50);
125138
border-radius: 2px;
126139
padding: 8px 16px 10px 16px;
140+
margin-left: auto;
141+
align-self: stretched;
127142
}
128143

129-
.status {
144+
.button--configure {
145+
background: none;
146+
border: none;
147+
box-shadow: none;
148+
color: #FFF;
149+
text-decoration: underline;
150+
}
151+
152+
.button--go-back {
153+
align-self: center;
154+
}
155+
156+
.subpage {
130157
position: fixed;
131158
top: 0;
132159
left: 0;
@@ -136,20 +163,23 @@ body {
136163
pointer-events: none;
137164
display: flex;
138165
flex-direction: column;
139-
align-items: center;
140-
justify-content: center;
141166
opacity: 0;
142167
will-change: opacity;
143168
transition: opacity 0.150s cubic-bezier(0,0,0.41,1);
144169
text-align: center;
145170
padding: 20px;
146171
}
147172

148-
.status--visible {
173+
.subpage--visible {
149174
opacity: 1;
150175
pointer-events: auto;
151176
}
152177

178+
.status {
179+
align-items: center;
180+
justify-content: center;
181+
}
182+
153183
.status__msg {
154184
font-size: 16px;
155185
margin: 8px;
@@ -164,9 +194,25 @@ body {
164194
}
165195

166196
.feedback {
197+
background: #49525F;
167198
position: absolute;
168-
bottom: 16px;
199+
bottom: 10px;
169200
left: 16px;
170201
width: 180px;
171202
line-height: 1.45;
172203
}
204+
205+
/* 1. scrollbar when extension is too small */
206+
.options {
207+
overflow: auto; /* [1] */
208+
}
209+
210+
.options__title {
211+
margin: 0 auto;
212+
}
213+
214+
.options__list {
215+
padding: 0;
216+
list-style: none;
217+
text-align: left;
218+
}

0 commit comments

Comments
 (0)