测试puppeteer模拟度检测

var puppeteer = require('puppeteer');
const devices = require('puppeteer/DeviceDescriptors');
const iphone = devices["iPhone 6"]
const path = require('path');
const pathToExtension = path.join(__dirname, './chrome-mac/Chromium.app/Contents/MacOS/Chromium');

const conf = {
    headless: false,
    executablePath: pathToExtension,
    defaultViewport: {
        width: 1300,
        height: 900
    }
}

puppeteer.launch(conf).then(
    async browser => {
            const page = await browser.newPage();

    await page.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36");
    await page.evaluateOnNewDocument(() => {
        delete navigator.__proto__.webdriver;
    });
    await page.evaluateOnNewDocument(() => {
        Object.defineProperty(navigator, 'plugins', {
            get: () => [1, 2, 3, 4, 5],
        });
    });
    await page.evaluateOnNewDocument(() => {
        Object.defineProperty(navigator, 'languages', {
            get: () => ['en-US', 'en'],
        });
    });
    await page.evaluateOnNewDocument(() => {
        Object.defineProperty(navigator, 'platform', {
            get: () => "Linux armxxxxx",
            configurable: true
        });
    });

    await page.evaluateOnNewDocument(() => {
        window.navigator.chrome = {
            runtime: {},
            getUserMedia: {},
        };
    });
    await page.goto(`https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html`);


    })
posted @ 2019-07-26 14:42  公众号python学习开发  阅读(962)  评论(0编辑  收藏  举报