3

Summery of the question
The question is about how I can incorporate javascript modules in python. I need to operate the fakebrowser's driver in python the same way it does in javascript so it can keep all the manipulated values of the browser fingerprint & system.


Full question
I have created an automated script for a website using selenium & python. What my code does is that it manages multiple accounts but after some time the website can detect that the accounts are being used from the same devices even after using various methods to make it undetectable (Proxies, User-Agent, Driver Options, and a ton more).

So the best module I found that can get my job done is fakebrowser because it can bypass most of the known ways websites use to detect automation. Fakebrowser can build a chromium driver but the problem I am facing is that it is using javascript and I don't want to rewrite all my code in javascript while I have already written it in Python (because I know only the basics in Javascript).

I have tried a lot of other solutions, below are only two of them but nothing I have tried so far have worked.


Attempt #1
I have tried using the chromium build which fakebrowser creates.

driver = webdriver.Chrome(executable_path=r"C:\Users\Hidden\.cache\puppeteer\chrome\win64-1069273\chrome-win\chrome.exe")
driver.get('https://pixelscan.com/') 

It still leaks most of the information about my system & browser fingerprint because most of the modifications to the browser are done when you open the chrome build using fakebrowser's module.


Attempt #2
I have tried to open the driver using javascript and then start controlling it using selenium python which I found in here: https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session


Fakebrowser Javascript Code

const {FakeBrowser} = require('fakebrowser');

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

!(async () => {
    const createBrowserAndGoto = async (userDataDir, url) => {
        const builder = new FakeBrowser.Builder()
            .vanillaLaunchOptions({
                headless: false,
                args: ['--remote-debugging-port=9223']
            })
            .userDataDir(userDataDir);

        const fakeBrowser = await builder.launch();
        const page = await fakeBrowser.vanillaBrowser.newPage();
        await page.goto(url);

        await sleep(1000000000);
        await fakeBrowser.shutdown();
    };

    createBrowserAndGoto('./fakeBrowserUserData1', 'http://pixelscan.net/').then(e => e);
})();

Selenium Python Code

from selenium import webdriver
from selenium.webdriver.chromium.options import ChromiumOptions


class Driver:
    def __init__(self):
        self.options = ChromiumOptions()
        self.options.add_experimental_option("debuggerAddress", "127.0.0.1:9223")
    
    def launch(self):
        driver = webdriver.Chrome(r"C:\Users\User\.cache\puppeteer\chrome\win64-1069273\chrome-win\chrome.exe", chrome_options=self.options)
        
        driver.get('http://pixelscan.net/')


Driver().launch()

Observation

Instead of connecting to the already open browser, it creates a new one but it's not using the same values as the fakebrowser driver does. So it's still leaking most of the information of my system & browser.

I need a way to control the same one that is already open or maybe I can use the driver variable created in JavaScript and pass it to the python code but I am not sure if that's even possible

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
MA19112001
  • 164
  • 2
  • 3
  • 16
  • 1
    What are you trying to achieve, what's your end goal? You're trying to fake the browser's fingerprint because ...[fill in the blanks]. – Barry the Platipus Feb 04 '23 at 21:57
  • I am trying to use fakebrowser module to fake the fingerprint of my browser because the website can detect I am having more then 1 account in their platform and they are banning all the accounts after linking them to each other. I need a way to run separate chrome drivers with different fingerprints. Other programs that manage to do what I am trying to achieve are: https://kameleo.io/ , https://www.adspower.com/ and https://pvabrowser.com/ – MA19112001 Feb 05 '23 at 01:14

1 Answers1

1

The fakebrowser package has two versions:

  • The basic version is puppeteer based which uses JavaScript hooks to modify properties and provides a simple api to make your web bot undetectable.
  • In the advanced version fakechrome recompiled Chromium to complete the simulation more robostly.

This usecase

Now you being able able to open the driver using javascript, but using Selenium-Python client when you initiate a new browsing session you still won't be able to attach it to the previous session.

This issue was discussed at length within the thread Allow webdriver to attach to a running browser.

@simon.m.stewart, WebDriver creator took a final call on this requirement as NotFeasible and further added:

I'm going to make a call on this one: it's a browser specific feature, and not something that we can implement in a general way. With IE, it's possible to iterate over the open windows in the OS and find the right IE process to attach to.

Firefox and Chrome, OTOH, need to be started in a specific mode and configuration, which means that just attaching to a running instance isn't technically possible.

Closing as "not feasible" here as this is a browser specific feature.


Conclusion

It's still not possible to attach webdriver to a running browser instance.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for your reply. If it's not possible to connect to an already open driver do you think there might be a way to save all the browser properties and relaunch a new driver in python with all the properties that fakebrowser used to build the driver. I just need a way to generate browser builds with different properties just like fakebrowser does. It doesn't really matter to me how it's done at this point because I have already spent 3 months with this. – MA19112001 Feb 08 '23 at 19:40