Search code examples
browser-automationkameleo

Kameleo Automation - get a unique and random Chrome version when creating profiles


I'm using Kameleo's local-api-client-python with Selenium to automate browser profile generation and browser actions.

I noticed that when I automate the profiles are being created with the same chrome version, how do I get that to be unique and random?

I'm using the example code provided in the README but every time Chrome is created with the same version. I need different versions

from kameleo.local_api_client.kameleo_local_api_client import KameleoLocalApiClient
from kameleo.local_api_client.builder_for_create_profile import BuilderForCreateProfile

client = KameleoLocalApiClient()
base_profiles = client.search_base_profiles(
    device_type='desktop',
    browser_product='chrome'
)

# Create a new profile with recommended settings
# for browser fingerprinting protection
create_profile_request = BuilderForCreateProfile \
    .for_base_profile(base_profiles[0].id) \
    .set_recommended_defaults() \
    .build()
profile = client.create_profile(body=create_profile_request)

# Start the browser
client.start_profile(profile.id)

Solution

  • When you call

    base_profiles = client.search_base_profiles(
        device_type='desktop',
        browser_product='chrome'
    )
    

    it will return 25 base profiles for the given filtering criteria. The first couple of elements of the list will have latest version of Chrome, but if you pick another element from the list you can get older versions as well.

    To get a profile with a random Chrome version each time, you can change the following code from this:

    create_profile_request = BuilderForCreateProfile \
        .for_base_profile(base_profiles[0].id) \
        .set_recommended_defaults() \
        .build()
    

    to this:

    create_profile_request = BuilderForCreateProfile \
        .for_base_profile(random.choice(base_profile).id \
        .set_recommended_defaults() \
        .build()
    

    Also import random at the TOP of your file