feat: low bandwidth mode (#294)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Joshua Higgins
2020-09-26 08:05:02 -04:00
committed by GitHub
parent eda6c85fc0
commit 0aa7ab596c
8 changed files with 41 additions and 2 deletions
+1
View File
@@ -10,6 +10,7 @@ EMAIL_PASSWORD=""
HEADLESS=""
IN_STOCK_WAIT_TIME=""
LOG_LEVEL=""
LOW_BANDWIDTH=""
MICROCENTER_LOCATION=""
OPEN_BROWSER=""
PAGE_TIMEOUT=""
+1
View File
@@ -77,6 +77,7 @@ Here is a list of variables that you can use to customize your newly copied `.en
| `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` |
| `IN_STOCK_WAIT_TIME` | Time to wait between requests to the same link if it has that card in stock | In seconds, default: `0` |
| `LOG_LEVEL` | [Logging levels](https://github.com/winstonjs/winston#logging-levels) | Debugging related, default: `info` |
| `LOW_BANDWIDTH` | Blocks images/fonts to reduce traffic (Note: disabled adblocker) | Default: `false` |
| `MICROCENTER_LOCATION` | Specific MicroCenter location to search | Default : `web` |
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
| `PAGE_TIMEOUT` | Navigation Timeout in milliseconds | `0` for infinite, default: `30000` |
+24
View File
@@ -5963,6 +5963,30 @@
}
}
},
"puppeteer-extra-plugin-block-resources": {
"version": "2.2.7",
"resolved": "https://registry.npmjs.org/puppeteer-extra-plugin-block-resources/-/puppeteer-extra-plugin-block-resources-2.2.7.tgz",
"integrity": "sha512-u2vcynnB9pINEVs7ZQs7DS8cJ2eedD0paL1M8ZdpNOQMCZ4zAVRwUpXF6T5v865nMu5srDnA3fTfdv6Ak0DG0g==",
"requires": {
"debug": "^4.1.1",
"puppeteer-extra-plugin": "^3.1.7"
},
"dependencies": {
"debug": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz",
"integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==",
"requires": {
"ms": "2.1.2"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"puppeteer-extra-plugin-stealth": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/puppeteer-extra-plugin-stealth/-/puppeteer-extra-plugin-stealth-2.6.1.tgz",
+1
View File
@@ -36,6 +36,7 @@
"puppeteer": "^5.3.1",
"puppeteer-extra": "^3.1.15",
"puppeteer-extra-plugin-adblocker": "^2.11.6",
"puppeteer-extra-plugin-block-resources": "^2.2.7",
"puppeteer-extra-plugin-stealth": "^2.6.1",
"pushbullet": "^2.4.0",
"pushover-notifications": "^1.2.2",
+1
View File
@@ -49,6 +49,7 @@ function envOrNumber(environment: string | undefined, number?: number): number {
const browser = {
isHeadless: envOrBoolean(process.env.HEADLESS),
isTrusted: envOrBoolean(process.env.BROWSER_TRUSTED, false),
lowBandwidth: envOrBoolean(process.env.LOW_BANDWIDTH, false),
maxBackoff: envOrNumber(process.env.PAGE_BACKOFF_MAX, 3600000),
maxSleep: envOrNumber(process.env.PAGE_SLEEP_MAX, 10000),
minBackoff: envOrNumber(process.env.PAGE_BACKOFF_MIN, 10000),
+8 -1
View File
@@ -5,11 +5,18 @@ import {adBlocker} from './adblocker';
import {fetchLinks} from './store/fetch-links';
import {getSleepTime} from './util';
import puppeteer from 'puppeteer-extra';
import resourceBlock from 'puppeteer-extra-plugin-block-resources';
import stealthPlugin from 'puppeteer-extra-plugin-stealth';
import {tryLookupAndLoop} from './store';
puppeteer.use(stealthPlugin());
puppeteer.use(adBlocker);
if (Config.browser.lowBandwidth) {
puppeteer.use(resourceBlock({
blockedTypes: new Set(['image', 'font'])
}));
} else {
puppeteer.use(adBlocker);
}
/**
* Starts the bot.
+1
View File
@@ -0,0 +1 @@
declare module 'puppeteer-extra-plugin-block-resources';
+4 -1
View File
@@ -42,6 +42,9 @@ export async function usingPage<T>(browser: Browser, cb: (page: Page, browser: B
}
export async function closePage(page: Page) {
await disableBlockerInPage(page);
if (!Config.browser.lowBandwidth) {
await disableBlockerInPage(page);
}
await page.close();
}