-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (28 loc) · 825 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import dotenv from 'dotenv';
dotenv.config();
import { GMAIL_URL } from './constants.js';
import {
login,
getUnreadEmailCount,
checkEnvironmentVariables,
} from './helpers/index.js';
puppeteer.use(StealthPlugin());
checkEnvironmentVariables();
const browser = await puppeteer.launch({
headless: 'new',
});
const [page] = await browser.pages();
await page.goto(GMAIL_URL);
// click on the sign in button
await page.waitForSelector('[data-action="sign in"]');
await page.click('[data-action="sign in"]');
try {
await login(page);
const unreadCount = await getUnreadEmailCount(page);
console.log(`You have ${unreadCount} unread emails.`);
} catch (error) {
console.error(error);
}
await browser.close();