Skip to content

Commit 8cf3841

Browse files
committed
about:blank navigation moved to before gatherer.beforeClass()
1 parent 39ae86a commit 8cf3841

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

lighthouse-core/gather/gather-runner.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const path = require('path');
3333
*
3434
* 2. For each pass in the config:
3535
* A. GatherRunner.beforePass()
36-
* i. all gatherer's beforePass()
36+
* i. navigate to about:blank
37+
* ii. all gatherer's beforePass()
3738
* B. GatherRunner.pass()
3839
* i. GatherRunner.loadPage()
39-
* a. navigate to about:blank
4040
* b. beginTrace (if requested) & beginNetworkCollect
4141
* c. navigate to options.url (and wait for onload)
4242
* ii. all gatherer's pass()
@@ -50,13 +50,27 @@ const path = require('path');
5050
* C. collect all artifacts and return them
5151
*/
5252
class GatherRunner {
53-
static loadPage(driver, options) {
54-
// Since a Page.reload command does not let a service worker take over, we
55-
// navigate away and then come back to reload. We do not `waitForLoad` on
56-
// about:blank since a page load event is never fired on it.
53+
/**
54+
* Loads about:blank and waits there briefly. Since a Page.reload command does
55+
* not let a service worker take over, we navigate away and then come back to
56+
* reload. We do not `waitForLoad` on about:blank since a page load event is
57+
* never fired on it.
58+
* @param {!Driver} driver
59+
* @return {!Promise}
60+
*/
61+
static loadBlank(driver) {
5762
return driver.gotoURL('about:blank')
58-
// Wait a bit for about:blank to "take hold" before switching back to the page.
59-
.then(_ => new Promise((resolve, reject) => setTimeout(resolve, 300)))
63+
.then(_ => new Promise((resolve, reject) => setTimeout(resolve, 300)));
64+
}
65+
66+
/**
67+
* Loads options.url with specified options.
68+
* @param {!Driver} driver
69+
* @param {!Object} options
70+
* @return {!Promise}
71+
*/
72+
static loadPage(driver, options) {
73+
return Promise.resolve()
6074
// Begin tracing only if requested by config.
6175
.then(_ => options.config.trace && driver.beginTrace())
6276
// Network is always recorded for internal use, even if not saved as artifact.
@@ -81,20 +95,19 @@ class GatherRunner {
8195
}
8296

8397
/**
84-
* Calls beforePass() on gatherers before navigation and before tracing has
85-
* started (if requested).
98+
* Navigates to about:blank and calls beforePass() on gatherers before tracing
99+
* has started and before navigation to the target page.
86100
* @param {!Object} options
87101
* @return {!Promise}
88102
*/
89103
static beforePass(options) {
90-
const config = options.config;
91-
const gatherers = config.gatherers;
104+
const pass = GatherRunner.loadBlank(options.driver);
92105

93-
return gatherers.reduce((chain, gatherer) => {
106+
return options.config.gatherers.reduce((chain, gatherer) => {
94107
return chain.then(_ => {
95108
return gatherer.beforePass(options);
96109
});
97-
}, Promise.resolve());
110+
}, pass);
98111
}
99112

100113
/**

lighthouse-core/test/gather/gather-runner-test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,6 @@ describe('GatherRunner', function() {
7979
});
8080
});
8181

82-
it('reloads a page via about:blank', () => {
83-
const expected = [
84-
'https://example.com',
85-
'about:blank'
86-
];
87-
const driver = {
88-
gotoURL(url) {
89-
assert(url, expected.pop());
90-
return Promise.resolve(true);
91-
},
92-
beginNetworkCollect() {
93-
return Promise.resolve();
94-
}
95-
};
96-
97-
return GatherRunner.loadPage(driver, {
98-
url: 'https://example.com',
99-
config: {}
100-
}).then(res => {
101-
assert.equal(res, true);
102-
});
103-
});
104-
10582
it('sets up the driver to begin emulation when mobile == true', () => {
10683
let calledEmulation = false;
10784
const driver = {

0 commit comments

Comments
 (0)