diff --git a/package.json b/package.json index caf56f4..23047c4 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,6 @@ "optionalDependencies": { "puppeteer": "^5.2.1", "puppeteer-extra": "^3.1.12", - "puppeteer-extra-plugin-stealth": "2.4.14" + "puppeteer-extra-plugin-stealth": "^2.4.14" } } diff --git a/src/login.ts b/src/login.ts index 7989760..350ea86 100644 --- a/src/login.ts +++ b/src/login.ts @@ -1,3 +1,4 @@ +import Browser from 'puppeteer'; import puppeteer from 'puppeteer-extra'; import pluginStealth from 'puppeteer-extra-plugin-stealth'; import * as readline from 'readline'; @@ -11,6 +12,7 @@ export async function login(email?: string, password?: string): Promise { puppeteer.use(pluginStealth()); + let browser: Browser.Browser; const headless = !process.argv.includes('-h'); const path = (): string => { if (process.argv.includes('-p')) { @@ -59,11 +61,24 @@ export async function login(email?: string, password?: string): Promise { if (executablePath) { options.executablePath = path(); } - const browser = await puppeteer.launch(options); + browser = await puppeteer.launch(options); + } catch (err) { + console.error( + 'Unable to open chromium brower. Install chromium manually and specify its path using the "-p" flag.', + ); + return; + } + + try { console.log('Opening chromium browser...'); const page = await browser.newPage(); const pages = await browser.pages(); pages[0].close(); + await page.evaluateOnNewDocument(() => { + const newProto = Object.getPrototypeOf(navigator); + delete newProto.webdriver; + Object.setPrototypeOf(navigator, newProto); + }); await page.goto('https://home.nest.com', { waitUntil: 'networkidle2' }); if (headless) { await page.waitForSelector('button[data-test="google-button-login"]');