你知唔知我系靓仔

puppeteer使用技巧

加载多个扩展

const ext1 = 'path to ext1';
const ext2 = 'path to ext2';
const ext3 = 'path to ext3';
const browser = await puppeteer.launch({
      headless: false,
      args: [`--disable-extensions-except=${ext1},${ext2},${ext3}`]
});

以逗号分隔的扩展名列表中没有空格

${ext1},${ext2},${ext3}

puppeteer去除webdriver标记

await page.evaluateOnNewDocument('const newProto = navigator.__proto__;delete newProto.webdriver;navigator.__proto__ = newProto;');

使用window.navigator.webdriver测试

输出undefined

去掉自动化提示

添加参数 ignoreDefaultArgs: true 或指定参数

ignoreDefaultArgs:['--enable-automation']

防止WebRTC泄露ip

await page.evaluateOnNewDocument( `navigator.mediaDevices.getUserMedia = navigator.webkitGetUserMedia = navigator.mozGetUserMedia = navigator.getUserMedia = webkitRTCPeerConnection = RTCPeerConnection = MediaStreamTrack = undefined;` );

#puppeteer/issues/4149

设置时区

await page.emulateTimezone('Asia/Makassar');

设置语言

args: ['--lang=en-GB']

设置经纬度

await page.setGeolocation({latitude: 39.923054, longitude: 130.451673});

ip-api https://api.ipgeolocation.io/

#puppeteer #自动化