问题
I tried:
const browser = await puppeteer.launch({args: ['--enable-webrtc-stun-origin=false', '--enforce-webrtc-ip-permission-check=false']});
But this is not working. Next I tried:
const targets = await browser.targets();
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
const backgroundPage = await backgroundPageTarget.page();
await backgroundPage.evaluateevaluateOnNewDocument(() => {
chrome.privacy.network.webRTCIPHandlingPolicy.set({
value: "default_public_interface_only"
});
});
But got:
TypeError: Cannot read property 'page' of undefined
EDIT: Need solution for {headless: true}.
回答1:
Here are steps to prevent webrtc IP leak on puppeteer version 1.9.0
.
Note:
- Background Pages are available for chrome extensions. You won't probably find a background page on a headless browser.
- Chrome headless does not support extensions. We must use
headless: false
.
Solution: WebRTC Leak Prevent
Clone the git repo to some local folder (ie: extensions/webrtc
),
git clone https://github.com/aghorler/WebRTC-Leak-Prevent extensions/webrtc
Use it inside your code,
const puppeteer = require('puppeteer');
async function helloWorld() {
// load the extension
const extensionPath = 'extensions/webrtc';
const browser = await puppeteer.launch({
// must be non-headless
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`,
],
});
const page = await browser.newPage();
// test it with browserleaks.com
await page.goto('https://browserleaks.com/webrtc');
// psss: just me hiding my details
await page.evaluate(() => $('#rtc-ipv4 a').css('-webkit-filter', 'blur(5px)'));
// taking evidence
await page.screenshot({ path: 'screenshots/browserleaks.png' });
await browser.close();
}
helloWorld();
Result:
Advanced Stuff
If you want to quickly hide both Public and Private IP from webRTC, modify this (extensions/webrtc/background.js
) line to disable_non_proxied_udp
,
来源:https://stackoverflow.com/questions/53017490/how-can-i-disable-webrtc-local-ip-leak-with-puppeteer