Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
puppeteer-extra exemple
import puppeteer, { BrowserContext } from 'puppeteer';
import { Browser , Page } from 'puppeteer';
let browser : Browser;
let browserCtx : BrowserContext;
let page : Page;
(async() => {
const browser = await puppeteer.connect({
browserWSEndpoint: 'browser endpoint', //the first file will log the url for the browser
});
const browserCtx = await browser.createIncognitoBrowserContext();
const page = await browserCtx.newPage();
//some tricks i found to make puppeteer undetectable in this link ttps://intoli.com/blog/making-chrome-headless-undetectable/
await page.evaluateOnNewDocument(() => {
Object.defineProperty(window, 'navigator', {
value: new Proxy(navigator, {
has: (target, key) => (key === 'webdriver' ? false : key in target),
get: (target, key) =>
key === 'webdriver'
? undefined
: typeof target[key] === 'function'
? target[key].bind(target)
: target[key]
})
})
})
await page.goto('https://mail.google.com/mail/' , { waitUntil: 'networkidle2' });
})()
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const AdblockerPlugin = require('puppeteer-extra-plugin-adblocker');
(async() => {
puppeteer.use(AdblockerPlugin({ blockTrackers: true }));
puppeteer.use(StealthPlugin());
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({userPrefs: {
webkit: {
webprefs: {
default_font_size: 16
}
}
}}))
let browser = await puppeteer.launch({
headless:false,
defaultViewport: null,
ignoreDefaultArgs: ['--disable-extensions'],
args: [
'--start-maximized',
'--no-sandbox',
'--disable-setuid-sandbox'
]
})
console.log(browser.wsEndpoint())
})().catch((error)=>{
console.error(error.message)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment