@@ -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 */
5252class 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 /**
0 commit comments