@@ -92,6 +92,18 @@ const browser = await puppeteer.launch({
92
92
defaultViewport : DEFAULT_VIEWPORT ,
93
93
} ) ;
94
94
95
+ // async function waitForNetworkIdle(page, idle='networkidle0') {
96
+ // return new Promise(resolve => {
97
+ // page._client.on('Page.lifecycleEvent', e => {
98
+ // if (e.name === 'networkIdle' && idle === 'networkidle0') {
99
+ // resolve();
100
+ // } else if (e.name === 'networkAlmostIdle' && idle === 'networkidle2') {
101
+ // resolve();
102
+ // }
103
+ // });
104
+ // });
105
+ // }
106
+
95
107
async function screenshotPageWithoutScroll ( url ) {
96
108
const context = await browser . createIncognitoBrowserContext ( ) ;
97
109
@@ -115,6 +127,7 @@ async function screenshotPageWithoutScroll(url) {
115
127
116
128
await page . goto ( url , { waitUntil : 'networkidle2' } ) ;
117
129
await page . waitFor ( WAIT_FOR ) ; // Wait a bit more in case other things are loading.
130
+ // await waitForNetworkIdle(page, 'networkidle0'); // wait for network to be idle.
118
131
const buffer = await page . screenshot ( {
119
132
path : argv . save ? argv . noscroll : null ,
120
133
fullPage : true
@@ -144,6 +157,7 @@ async function screenshotPageAfterScroll(url) {
144
157
} ) ;
145
158
146
159
await page . waitFor ( WAIT_FOR ) ; // Wait a bit more in case other things are loading.
160
+ // await waitForNetworkIdle(page, 'networkidle0'); // wait for network to be idle.
147
161
148
162
// const maxScrollHeight = await page.evaluate(
149
163
// 'document.scrollingElement.scrollHeight');
0 commit comments