How can I disable webRTC local IP leak with puppeteer?

流过昼夜 提交于 2019-12-07 08:20:30

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,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!