1

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}.

KisaGut
  • 65
  • 2
  • 7

1 Answers1

8

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:

enter image description here

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,

Md. Abu Taher
  • 17,395
  • 5
  • 49
  • 73
  • Thank you very much! Solution works fine, but ...... headless: false =((! Do you have any solutions for headless: true pls?Or some links for read =). – KisaGut Oct 27 '18 at 14:57
  • Unfortunately not. You can try with xvfb though. Is that okay, I'll share some resources if you need? Also mark as accepted if the solution works fine. ;) – Md. Abu Taher Oct 27 '18 at 17:08
  • Ok, marked. Yes, share pls i need all info =). Maybe you know how to re-compile chromium without #if BUILDFLAG(ENABLE_WEBRTC) and also spoof system time? Some resources, it would be nice! Sorry for my English. – KisaGut Oct 27 '18 at 19:09
  • Building chromium takes a lot of time. I wonder why headless is a must. – Md. Abu Taher Oct 28 '18 at 03:20
  • Look at these answers, https://stackoverflow.com/a/51683309/6161265 and https://stackoverflow.com/a/53020614/6161265 – Md. Abu Taher Oct 28 '18 at 03:22
  • Ok, thx for great resources! I will try headful than! Maybe you can help me with that https://stackoverflow.com/questions/53027538/how-to-set-change-or-block-timezonesystemtime-with-puppeteer . Thank you in advance for the great help =). – KisaGut Oct 28 '18 at 10:08
  • I've updated this answer and also provided answer to that question. – Md. Abu Taher Oct 28 '18 at 11:47
  • @Md.AbuTaher How to use extensions on windows puppeteer ? – rock stone Mar 10 '23 at 08:17