Wiki

Home / Developer Guide
You can use the scripts below to manage Chameleon with a browser automation library.

Launch a browser with Chameleon

  • Python
  
    from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep

firefox_binary = '/usr/bin/firefox'
driver = webdriver.Firefox(firefox_binary=firefox_binary, executable_path='./geckodriver')
extension_path = '/path/to/chameleon/ext.xpi'
driver.install_addon(extension_path, temporary=True)

driver.get('about:debugging#/runtime/this-firefox')

# wait for extensions to appear
wait = WebDriverWait(driver, 5)
element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'card')))

# internal uuid for extension pages
internal_uuid = driver.execute_script("""
  let extensions = Array.from(document.querySelectorAll('.card'));
  let chameleon = extensions.filter(el => el.querySelector('span').title == 'Chameleon')[0];
  let metadata = Array.from(chameleon.querySelectorAll('.fieldpair__description')).map(e => e.innerText);
  return metadata[2];
""")

POPUP_PAGE = f'moz-extension://{internal_uuid}/popup/popup.html'
OPTIONS_PAGE = f'moz-extension://{internal_uuid}/options/options.html'

# navigate to chameleon popup page
driver.get(POPUP_PAGE)

# select profile tab
driver.find_element_by_id('profileTab').click()

# select Random Desktop profile option
driver.find_element_by_id('randomDesktop').click()

# verify user agent changed
driver.get('https://httpbin.org/headers')

sleep(10)

driver.quit()
  

Import Settings

  • Python
  
    # navigate to chameleon options page
driver.get(OPTIONS_PAGE)

# import settings
driver.find_element_by_id('chameleonImport').send_keys('/path/to/settings.json')

# wait for chameleon to reload
sleep(3)
  

Browser Profiles

When selecting a specfic browser profile to use, you can use the browser profile ID as a selector. Profile IDs are made from a combination of an OS and a browser such as "win1-edg". Listed below are OS IDs and the browser abbreviations that Chameleon uses.

OS ID
Windows 7 win1
Windows 8 win2
Windows 8.1 win3
Windows 10 win4
macOS 10.13 (or 2 behind latest) mac1
macOS 10.14 (or 1 behind latest) mac2
macOS 10.15 (or latest) mac3
Linux lin1
Ubuntu Linux lin2
Fedora Linux lin3
iOS 11 (or 2 behind latest) ios1
iOS 12 (or 1 behind latest) ios2
iOS 13 (or latest) ios3
Android 6 (or 4 behind latest) and1
Android 7 (or 3 behind latest) and2
Android 8 (or 2 behind latest) and3
Android 9 (or 1 behind latest) and4
Browser ID
Chrome gcr (desktop) / gcrm (mobile) / gcrt (tablet)
Edge edg (desktop) / edgm (mobile)
Firefox ff (desktop) / ffm (mobile) / fft (tablet)
Internet Explorer ie
Safari sf (desktop) / sfm (iPhone) / sft (iPad)

Controlling Chameleon with an Addon

  • JavaScript
  
    // You'll need to use the developer build of Chameleon if you want to
// control Chameleon with another extension
// https://github.com/sereneblue/chameleon/releases

// change browser profile to Windows 10 - Firefox
await browser.runtime.sendMessage(
  '{3579f63b-d8ee-424f-bbb6-6d0ce3285e6a}',
  {
    action: 'updateProfile',
    data: 'win4-ff',
  },
  null
);

// import settings by using the settings exported by Chameleon
// let settings = exported settings loaded as an object  
// saving settings is also how changes are persisted after reloading the extension
await browser.runtime.sendMessage(
  '{3579f63b-d8ee-424f-bbb6-6d0ce3285e6a}',
  {
    action: 'implicitSave'
  },
  null
);

// get current Chameleon settings
let settings = await browser.runtime.sendMessage(
  '{3579f63b-d8ee-424f-bbb6-6d0ce3285e6a}',
  {
    action: 'getSettings'
  },
  null
);

// The logic for how messages are routed is mostly handled in this file
// https://github.com/sereneblue/chameleon/blob/develop/src/store/actions.ts