fingerprint-suite icon indicating copy to clipboard operation
fingerprint-suite copied to clipboard

Can it be combined with Selenium + Python ?

Open zerolimits303 opened this issue 2 years ago • 3 comments

I think this is a very nice library but I don't know if it can be combined with Selenium with Python? Thanks.

zerolimits303 avatar Mar 06 '22 05:03 zerolimits303

I am not familiar with selenium very well. If it allows you to inject a javascript code, it can be combined. I will add this feature to the V2. You can then get only the string to evaluate to override the fingerprint in the browser.

petrpatek avatar Mar 13 '22 15:03 petrpatek

I am not familiar with selenium very well. If it allows you to inject a javascript code, it can be combined. I will add this feature to the V2. You can then get only the string to evaluate to override the fingerprint in the browser.

@petrpatek Hi! Have you implemented such a feature? And if so, can you give me an example?

ja3abuser avatar Sep 01 '22 22:09 ja3abuser

Hello! Sorry, I'm not @petrpatek but I hope I can answer your questions just as well :)

The support for this is still unofficial, so it requires a bit of hacking. Consider the following snippet:

import {FingerprintInjector}  from 'fingerprint-injector';
import {FingerprintGenerator} from 'fingerprint-generator';

const injector = new FingerprintInjector();
const generator = new FingerprintGenerator();
const fingerprint = generator.getFingerprint({
    'devices': ['desktop'],
    'operatingSystems': ['windows'],
    // ... your fingerprint options
});

const injectable_code = injector['getInjectableScript'](fingerprint);
// driver.execute_async_script(injectable_code) ...?

See the second line from the bottom - calling injector.getInjectableScript with the fingerprint as an argument returns JS code (as string), which you can then run in your browser (using Selenium, any other browser automation tool, or even copy-paste it to the browser console). With some extra elbow grease, you can even pass this string to your Python Selenium script, if that's the case. Note that we use the square bracket property accessor here (instead of .), as getInjectableScript is a private property of the FingerprintInjector class.

Last but not least - this handles only part of the injection - make sure to set the browser launch arguments (e.g. screen size, etc.) correctly, so it's in line with the "in-browser" injected features.

In case of any problems, feel free to leave another comment. Thank you for reaching out to us!

barjin avatar Sep 02 '22 12:09 barjin

Sorry for the one last ping - closing this with wontfix, but the working solution is in the comment above :)

barjin avatar Dec 01 '22 17:12 barjin

inject a javascript code

Hi, selenium+chrome could inject a JavaScript just by few lines python code if there is a Jave script inject file! I think they could combine perfect! Thanks! I am very happy willing to see it!

stevenhubhub avatar Feb 10 '23 02:02 stevenhubhub

selenium+chrome support: If could combine fingerprint's package into a single Js file, could execute it directly in python to complete the injection, which takes about 3 lines of code. All need to do is call a python wrapped method, which automatically interacts with selenium. Instead of programming directly to selenium, here is the code for the python example: with open(f"fingerprint*.js", encoding='utf-8') as f1... driver. execute_cdp_cmd (' fingerprint *. Js')

stevenhubhub avatar Feb 10 '23 03:02 stevenhubhub