puppeteer-autoscroll-down
Advanced tools
Comparing version 1.1.2 to 2.0.0
@@ -5,2 +5,8 @@ # Change Log | ||
## 2.0.0 | ||
- Dropped support for CommonJS | ||
- Fixed type compatibility issue between puppeteer-core and puppeteer. | ||
- Upgraded devDependencies. | ||
## 1.1.2 | ||
@@ -7,0 +13,0 @@ |
@@ -1,3 +0,1 @@ | ||
import { Page } from 'puppeteer-core' | ||
export type Options = { | ||
@@ -34,7 +32,7 @@ /** | ||
* ``` | ||
* @param {Page} page | ||
* @param {Object} page | ||
* @param {Options} options | ||
* @returns {Promise<number>} | ||
*/ | ||
export declare function scrollPageToBottom(page: Page, options: Options): Promise<number> | ||
export declare function scrollPageToBottom(page: object, options: Options): Promise<number> | ||
@@ -52,6 +50,6 @@ /** | ||
* ``` | ||
* @param {Page} page | ||
* @param {Object} page | ||
* @param {Options} options | ||
* @returns {Promise<number>} | ||
*/ | ||
export declare function scrollPageToTop(page: Page, options: Options): Promise<number> | ||
export declare function scrollPageToTop(page: object, options: Options): Promise<number> |
function scrollPage(scrollDirection) { | ||
return async (page, { size = 250, delay = 100, stepsLimit = null } = {}) => { | ||
return async (page, { delay = 100, size = 250, stepsLimit = null } = {}) => { | ||
let lastScrollPosition = await page.evaluate( | ||
@@ -7,3 +7,3 @@ async (pixelsToScroll, delayAfterStep, limit, direction) => { | ||
if (!element) return 0 | ||
let { scrollHeight, offsetHeight, clientHeight } = element | ||
let { clientHeight, offsetHeight, scrollHeight } = element | ||
return Math.max(scrollHeight, offsetHeight, clientHeight) | ||
@@ -49,2 +49,4 @@ } | ||
module.exports = { scrollPageToBottom: scrollPage('bottom'), scrollPageToTop: scrollPage('top') } | ||
export const scrollPageToBottom = scrollPage('bottom'); | ||
export const scrollPageToTop = scrollPage('top'); |
{ | ||
"name": "puppeteer-autoscroll-down", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Handle infinite scroll on websites with puppeteer", | ||
@@ -8,4 +8,5 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
}, | ||
"type": "module", | ||
"license": "MIT", | ||
@@ -32,15 +33,17 @@ "author": "mbalabash <maksim.balabash@gmail.com>", | ||
"devDependencies": { | ||
"@logux/eslint-config": "^49.0.0", | ||
"@logux/eslint-config": "^52.0.2", | ||
"@types/puppeteer": "^7.0.4", | ||
"eslint": "^8.36.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-n": "^15.6.1", | ||
"eslint": "^8.54.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-n": "^16.3.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-node-import": "^1.0.4", | ||
"eslint-plugin-perfectionist": "^2.4.0", | ||
"eslint-plugin-prefer-let": "^3.0.1", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"find-chrome-bin": "1.0.3", | ||
"puppeteer-core": "^19.8.0", | ||
"find-chrome-bin": "2.0.0", | ||
"puppeteer-core": "^21.5.2", | ||
"tsm": "^2.3.0", | ||
"typescript": "^5.0.2", | ||
"typescript": "^5.3.2", | ||
"uvu": "^0.5.6" | ||
@@ -47,0 +50,0 @@ }, |
@@ -1,17 +0,19 @@ | ||
const { test } = require('uvu') | ||
const { join } = require('path') | ||
const assert = require('uvu/assert') | ||
const puppeteer = require('puppeteer-core') | ||
const { findChrome } = require('find-chrome-bin') | ||
const { PUPPETEER_REVISIONS } = require('puppeteer-core/lib/cjs/puppeteer/revisions.js') | ||
import { findChrome } from 'find-chrome-bin' | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url'; | ||
import puppeteer from 'puppeteer-core' | ||
import { PUPPETEER_REVISIONS } from 'puppeteer-core/lib/cjs/puppeteer/revisions.js' | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
const { scrollPageToBottom, scrollPageToTop } = require('../index') | ||
import { scrollPageToBottom, scrollPageToTop } from '../index.js' | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
test('should scroll `regular` page to bottom', async () => { | ||
let chromeInfo = await findChrome({ | ||
download: { puppeteer, revision: PUPPETEER_REVISIONS.chromium, path: join(__dirname, 'chrome') } | ||
download: { path: join(__dirname, 'chrome'), puppeteer, revision: PUPPETEER_REVISIONS.chromium } | ||
}) | ||
let browser = await puppeteer.launch({ | ||
headless: true, | ||
executablePath: chromeInfo.executablePath | ||
executablePath: chromeInfo.executablePath, | ||
headless: true | ||
}) | ||
@@ -40,7 +42,7 @@ let isScrolledToBottom = false | ||
let chromeInfo = await findChrome({ | ||
download: { puppeteer, revision: PUPPETEER_REVISIONS.chromium, path: join(__dirname, 'chrome') } | ||
download: { path: join(__dirname, 'chrome'), puppeteer, revision: PUPPETEER_REVISIONS.chromium } | ||
}) | ||
let browser = await puppeteer.launch({ | ||
headless: true, | ||
executablePath: chromeInfo.executablePath | ||
executablePath: chromeInfo.executablePath, | ||
headless: true | ||
}) | ||
@@ -80,7 +82,7 @@ let isScrolledToBottom = false | ||
let chromeInfo = await findChrome({ | ||
download: { puppeteer, revision: PUPPETEER_REVISIONS.chromium, path: join(__dirname, 'chrome') } | ||
download: { path: join(__dirname, 'chrome'), puppeteer, revision: PUPPETEER_REVISIONS.chromium } | ||
}) | ||
let browser = await puppeteer.launch({ | ||
headless: true, | ||
executablePath: chromeInfo.executablePath | ||
executablePath: chromeInfo.executablePath, | ||
headless: true | ||
}) | ||
@@ -87,0 +89,0 @@ let lastPosition = 0 |
Sorry, the diff of this file is not supported yet
62189
189
Yes
16