Use chrome extension option to manipulate browser finger print

Hi Team,

I have a case where i need to manipulate browser finger print to send unique request to server. manually on in general case we use chrome extension ( example - fingerprintspoof.crx ).

robot framework example -

Call Method ${chrome_options} add_extension /root/fingerprintspoof.crx

how can i user similar extension with k6 browser

@arvindpatel5788

I was able to enable a chrome extension, but it seems to be a big hack. I don’t know if it fits your needs.

  • So first of all I can’t load .crx file, I had to unpack it into a local folder next to the script.js (folder name e.g.: extensionsrc)
  • I had to use K6_BROWSER_ARGS=“load-extension=extensionsrc” to load the extension on startup
  • I also had to use K6_BROWSER_IGNORE_DEFAULT_ARGS=“disable-extensions” so xk6-browser will not set the disable-extensions flag
  • The xk6-browser uses incognito like pages, and extensions in incognito mode can’t be enabled from command line, so we have to navigate to chrome://extensions page and enable the extension in incognito mode (this can be made from the test script)

So the whole process:

  • download the extension source code (I used the CRX Extractor/Downloader chrome extension for this purpose, and downloaded the Allow CORS extension in zip format for example )
  • unzipped the downloaded extension next to the script.js
  • started the script with: K6_BROWSER_HEADLESS=false K6_BROWSER_ARGS="load-extension=extensionsrc" K6_BROWSER_IGNORE_DEFAULT_ARGS="disable-extensions" k6 run script.js

script.js:

import { browser } from 'k6/experimental/browser';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      vus: 1,
      iterations: 1,
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  }
}

export default async function () {
  const page = browser.newPage();
  try {
    await page.goto('chrome://extensions');
    sleep(3)
    const button = page.waitForSelector('cr-button[id="detailsButton"]');
    await button.click();
    sleep(3)
    const togglerow = page.waitForSelector('extensions-toggle-row[id="allow-incognito"]');
    await togglerow.click();
    sleep(3)
    page.goto('https://k6.io')
    sleep(20)
  } finally {
    page.close();
  }
}

Here is a screencast of the result:

Screencast

1 Like

Thanks @bandorko this is what i am looking for.
let me try

Hi @bandorko

i am running script on window 11. trying to work with https://chromewebstore.google.com/detail/fingerprint-spoofing/ljdekjlhpjggcjblfgpijbkmpihjfkni

i download zip and unzipped it on given folder.

ran following commands to run load test

set K6_BROWSER_ARGS="load-extension=C:\Users\arvind\loadtest\loadtest\fingerprintspoof" && set K6_BROWSER_IGNORE_DEFAULT_ARGS=“disable-extensions” && k6 run stress-tests\profile_1.js

Browser getting opened but i dont see extension been install on browser

@arvindpatel5788

I tried on Ubuntu, but If I have time I will try it on windows also.

1 Like

@arvindpatel5788

I wasn’t able to make it work in windows either, because on windows chrome wants to open the extensions page in a non-incognito window, and k6 crashes on it for me, but here is another workaround I hope it is usable for you:

the script now is just like that:

import { browser } from 'k6/experimental/browser';
import { sleep } from 'k6';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      vus: 1,
      iterations: 1,
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  }
}

export default async function () {
  const page = browser.newPage();
  try {
    page.goto('https://k6.io')
    sleep(300)
  } finally {
    page.close();
  }
}

I placed it C:\example\script.js
I copied the extension source to C:\example\extensionsrc

I run the following command:
set "K6_BROWSER_HEADLESS=false" && set "K6_BROWSER_ARGS=load-extension=C:\example\extensionsrc,user-data-dir=C:\example\datadir" && set "K6_BROWSER_IGNORE_DEFAULT_ARGS=disable-extensions" && k6 run C:\example\script.js
At first run you will see, that the chrome extension is not enabled, so you open the chrome:\\extensions url, and enable the incognito mode for the given chrome extension.

Because of the user-data-dir command line option this setting will be saved into c:\example\datadir, so when you next run the command, the chrome extension will be enabled by default for the incognito window also.

I hope this helps.