Skip to content

Commit 524d5ed

Browse files
committed
lazy images: add placeholder waitForNetworkIdle
1 parent 2392166 commit 524d5ed

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lazyimages_without_scroll_events.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ const browser = await puppeteer.launch({
9292
defaultViewport: DEFAULT_VIEWPORT,
9393
});
9494

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+
95107
async function screenshotPageWithoutScroll(url) {
96108
const context = await browser.createIncognitoBrowserContext();
97109

@@ -115,6 +127,7 @@ async function screenshotPageWithoutScroll(url) {
115127

116128
await page.goto(url, {waitUntil: 'networkidle2'});
117129
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.
118131
const buffer = await page.screenshot({
119132
path: argv.save ? argv.noscroll : null,
120133
fullPage: true
@@ -144,6 +157,7 @@ async function screenshotPageAfterScroll(url) {
144157
});
145158

146159
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.
147161

148162
// const maxScrollHeight = await page.evaluate(
149163
// 'document.scrollingElement.scrollHeight');

0 commit comments

Comments
 (0)