Skip to content

Commit 746ff2e

Browse files
committed
docs(recipes): update custom-gatherer-puppeteer to use FR (#13940)
1 parent 66b46ee commit 746ff2e

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

docs/recipes/custom-gatherer-puppeteer/custom-config.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
*/
66

77
export default {
8-
passes: [{
9-
passName: 'defaultPass',
10-
gatherers: [
11-
'custom-gatherer',
12-
],
13-
}],
8+
artifacts: [
9+
{id: 'CustomGatherer', gatherer: 'custom-gatherer'},
10+
],
11+
12+
navigations: [
13+
{
14+
id: 'default',
15+
artifacts: [
16+
'CustomGatherer',
17+
],
18+
},
19+
],
1420

1521
audits: [
1622
'custom-audit',

docs/recipes/custom-gatherer-puppeteer/custom-gatherer.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,15 @@
77
/* global document */
88

99
import {Gatherer} from 'lighthouse';
10-
import puppeteer from 'puppeteer';
11-
12-
async function connect(driver) {
13-
const browser = await puppeteer.connect({
14-
browserWSEndpoint: await driver.wsEndpoint(),
15-
defaultViewport: null,
16-
});
17-
const {targetInfo} = await driver.sendCommand('Target.getTargetInfo');
18-
const puppeteerTarget = (await browser.targets())
19-
.find(target => target._targetId === targetInfo.targetId);
20-
const page = await puppeteerTarget.page();
21-
return {browser, page, executionContext: driver.executionContext};
22-
}
2310

2411
class CustomGatherer extends Gatherer {
25-
async afterPass(options) {
26-
const {driver} = options;
27-
const {page, executionContext} = await connect(driver);
12+
meta = {
13+
supportedModes: ['navigation', 'timespan', 'snapshot'],
14+
};
15+
16+
async getArtifact(context) {
17+
const {driver, page} = context;
18+
const {executionContext} = driver;
2819

2920
// Inject an input field for our debugging pleasure.
3021
function makeInput() {
@@ -41,8 +32,6 @@ class CustomGatherer extends Gatherer {
4132
const value = await executionContext.evaluateAsync(`document.querySelector('input').value`);
4233
if (value !== '123') throw new Error('huh?');
4334

44-
// No need to close the browser or page. Puppeteer doesn't own either of them.
45-
4635
return {value};
4736
}
4837
}

docs/recipes/custom-gatherer-puppeteer/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# Make sure we're in this `docs/recipes/customer-gatherer-puppeteer` directory
44
cd "$(dirname "$0")"
55

6-
node node_modules/.bin/lighthouse --legacy-navigation --config-path=custom-config.js https://www.example.com --output=json |
6+
node node_modules/.bin/lighthouse --config-path=custom-config.js https://www.example.com --output=json |
77
jq '.audits["custom-audit"].score' |
88
grep -q 1

0 commit comments

Comments
 (0)