Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
add stealth fix to login
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandawg93 committed Aug 2, 2020
1 parent eb6795c commit b52cc92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 16 additions & 1 deletion src/login.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,6 +12,7 @@ export async function login(email?: string, password?: string): Promise<void> {

puppeteer.use(pluginStealth());

let browser: Browser.Browser;
const headless = !process.argv.includes('-h');
const path = (): string => {
if (process.argv.includes('-p')) {
Expand Down Expand Up @@ -59,11 +61,24 @@ export async function login(email?: string, password?: string): Promise<void> {
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"]');
Expand Down

0 comments on commit b52cc92

Please sign in to comment.