Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add incognito mode #534

Merged
merged 7 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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