Skip to content

Commit

Permalink
feat: add incognito mode (#534)
Browse files Browse the repository at this point in the history
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
  • Loading branch information
Sethtrosity and jef committed Oct 20, 2020
1 parent 5ea7cc4 commit 2b6457e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -88,6 +88,7 @@ Here is a list of variables that you can use to customize your newly copied `.en
| `EMAIL_TO` | Destination Email | Defaults to username if not set. Can be comma separated |
| `EMAIL_USERNAME` | Gmail address | E.g.: `jensen.robbed.us@gmail.com` |
| `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` |
| `INCOGNITO` | Puppeteer to run incognito or not | Debugging related, default: `false` |
| `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 | Disables ad blocker, default: `false` |
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Expand Up @@ -109,6 +109,7 @@ function envOrNumberMax(environmentMin: string | undefined, environmentMax: stri

const browser = {
isHeadless: envOrBoolean(process.env.HEADLESS),
isIncognito: envOrBoolean(process.env.INCOGNITO, false),
isTrusted: envOrBoolean(process.env.BROWSER_TRUSTED, false),
lowBandwidth: envOrBoolean(process.env.LOW_BANDWIDTH, false),
maxBackoff: envOrNumberMax(process.env.PAGE_BACKOFF_MIN, process.env.PAGE_BACKOFF_MAX, 3600000),
Expand Down
7 changes: 5 additions & 2 deletions src/store/lookup.ts
Expand Up @@ -35,7 +35,8 @@ async function lookup(browser: Browser, store: Store) {
continue;
}

const page = await browser.newPage();
const context = (config.browser.isIncognito ? await browser.createIncognitoBrowserContext() : browser.defaultBrowserContext());
const page = (config.browser.isIncognito ? await context.newPage() : await browser.newPage());
page.setDefaultNavigationTimeout(config.page.timeout);
await page.setUserAgent(config.page.userAgent);

Expand All @@ -62,8 +63,10 @@ async function lookup(browser: Browser, store: Store) {
// used to detect bot traffic, it introduces a 5 second page delay
// before redirecting to the next page
await processBackoffDelay(store, link, statusCode);

await closePage(page);
if (config.browser.isIncognito) {
await context.close();
}
}
/* eslint-enable no-await-in-loop */
}
Expand Down

0 comments on commit 2b6457e

Please sign in to comment.