Fixed infinite scroll

This commit is contained in:
drobnikj 2019-01-08 13:01:31 +01:00
parent 84b4040a0b
commit 3b87790d07

View File

@ -35,10 +35,10 @@ const getPageScrollInfo = (page, elementToScroll) => page.evaluate((elementToScr
module.exports = async (page, maxHeight, elementToScroll = 'body') => {
const maybeResourceTypesInfiniteScroll = ['xhr', 'fetch', 'websocket', 'other'];
const stringifyScrollInfo = (scrollInfo) => {
return `scrollTop=${scrollInfo.scrollTop}, ` +
`clientHeight=${scrollInfo.clientHeight}, ` +
`scrollHeight=${scrollInfo.scrollHeight}, ` +
`maxHeight=${maxHeight}`;
return `scrollTop=${scrollInfo.scrollTop}, `
+ `clientHeight=${scrollInfo.clientHeight}, `
+ `scrollHeight=${scrollInfo.scrollHeight}, `
+ `maxHeight=${maxHeight}`;
};
const defaultScrollDelay = 3000;
const defaultElementTimeout = 60000;
@ -72,7 +72,6 @@ module.exports = async (page, maxHeight, elementToScroll = 'body') => {
}
});
try {
await page.waitForSelector(elementToScroll, { timeout: defaultElementTimeout });
let scrollInfo = await getPageScrollInfo(page, elementToScroll);
logInfo(`Infinite scroll started (${stringifyScrollInfo(scrollInfo)}).`);
@ -121,8 +120,4 @@ module.exports = async (page, maxHeight, elementToScroll = 'body') => {
}
page.removeAllListeners('request');
logInfo(`Infinite scroll finished (${stringifyScrollInfo(scrollInfo)} resourcesStats=${JSON.stringify(resourcesStats)})`);
} catch (err) {
// Infinite scroll should not break whole crawler
logError('An exception thrown in infiniteScroll()', err);
}
};