0

I am using Playwright for testing multi-account browsing therefore leveraging proxy and emulating geolocations, time-zone is useful. but some website eg: https://browserleaks.com/ip are still able to detect my public ip which is leads to DNS leak problem. Is there any way to emulate WebRTC public IP using Playwright Java?

Here I am able to emulate geolocation, timezone etc but not WebRTC

Playwright playwright = Playwright.create();
Browser browser = playwright.firefox().launch(new BrowserType.LaunchOptions().setHeadless(false));
BrowserContext brcx = browser.newContext(new Browser.NewContextOptions()
                        .setScreenSize(1080,720)
                        .setTimezoneId("EET")
                        .setGeolocation(58.595402,25.052695)
                        .setViewportSize(1080,720)
                        .setProxy(new Proxy("proxy-url")
                                .setUsername("username")
                                .setPassword("password"))

        );
        Page page = brcx.newPage();
        page.navigate("https://whoer.net/");

2 Answers2

2

It's possible in to do in chromium based browsers via extensions. However, keep in mind that this will only work in headful mode. Also, the code I will be providing is in python, but that is mostly irrelevant since you can translate it to any other supported language easily. Here's how to do it:

  1. Firstly, decide on an extension that can disable WebRTC that you want to use. I will be using WebRTC Leak Prevent, which has the extension id of eiadekoaikejlgdbkbdfeijglgfdalml.

  2. Then get the .crx file of the extension. There are numerous ways to do it, and even some extensions which you can use to automate it. Extract the .crx file in a separate directory, we'll need this later.

  3. Now, since we'll be loading it on every playwright run, you'll need to fix the extension id. To do this, open your normal chrome browser and download the extension. After it's downloaded, make a note of it's extension id. You can do this by heading over to chrome://extensions and noting down the corresponding id. Then head over to the directory where chrome stores the extension data, and click on the folder that matches the id you just copied down. From here, you want to copy the manifest.json file over to the directory where you extracted the .crx file. Alternatively, you can also follow this answer to achieve the same results.

  4. Once this is done, you can now load the extension as many times as you want. Simply use the args (java equivalent is setArgs) to pass additional command line flags that load the extension when launching the browser:

    ext = 'path/to/extension/root'
    browser = playwright.chromium.launch(headless=False, args=[f'--disable-extensions-except={ext}',
                                                               f'--load-extension={ext}'])
    
  5. Now, because playwright normally uses incognito mode for it's contexts, and the fact that extensions are disabled by default in incognito mode, you will need to enable the extension for that particular browser instance (only need to be done once per browser). You can do this by opening a new page, navigating to chrome://extensions and executing the following javascript using the page.evaluate method and the extension id of the extension:

    extID = 'eiadekoaikejlgdbkbdfeijglgfdalml'
    page = browser.new_page()
    page.goto('chrome://extensions', timeout=0)
    page.evaluate(
    f'chrome.developerPrivate.updateExtensionConfiguration({{extensionId: "{extID}", incognitoAccess: true}})')
    page.close()
    

Once this is done, the extension is enabled and will block webrtc

Charchit Agarwal
  • 2,829
  • 2
  • 8
  • 20
  • blocking webrtc creates recaptcha problem e.g. Google .com Confirm are you not a robot. Many websites blocklist us when they are unable to detect webrtc on browser? How to mimic ,emulate or reproduct fake webrtc ip just like Kameleo browser does –  Aug 23 '22 at 06:00
  • @NeerajVerma It does not create a problem unless the website is ready to have a lot of false negatives. Having webrtc disabled might make you stand out more when fingerprinting, but enough people do it to not make it conclusive. It's more likely that the rest of your setup is faulty. – Charchit Agarwal Aug 23 '22 at 07:21
  • @NeerajVerma However, you can try this workaround instead: https://stackoverflow.com/q/71002314/16310741, additionally, according to [this](https://stackoverflow.com/a/72489543/16310741) post, you can try this extension as well which might do what you are looking for: https://chrome.google.com/webstore/detail/webrtc-network-limiter/npeicpdbkakmehahjeeohfdhnlpdklia?hl=en – Charchit Agarwal Aug 23 '22 at 07:23
  • the chrome extension you recommended is not updated since 2016 and no more functional for present. any other option available to archive the same thing which this extension does for present? –  Aug 27 '22 at 19:46
0

@Charchit has a nice workaround. I have a paid suggestion for you. Kameleo is a "stealth browsing platform" that can be easily integrated with Playwright. It will take care of DNS leaks and it will automatically mask your WebRTC public and private IP based on your selection or on your proxy's external IP address. Also, it takes care of every aspect of your browser fingerprint. It is the easiest way to scrape without being flagged as a bot. The more extensions like the above you install, the more inconsistent the browser fingerprint will be, and you will be flagged as a bot, and you will receive several captchas. Kameleo both supports Chromium-based browsers and Firefox.

For further information, you should check their Getting Started guide, and the tutorial on integrating with Playwright.

TL;DR; They have a nice video here

Tomi
  • 3,370
  • 1
  • 16
  • 26
  • its 2x pricy for automation support, that's too expensive for beginners –  Aug 23 '22 at 12:20
  • I agree, for start, you can do with the above solution. If you are ready to scale your business you should consider using Kameleo so you won't have to care about bot detection systems anymore. – Tomi Aug 23 '22 at 14:13