Running xk6 binary, cannot start browser error makes me a sad panda

Hi there,I LOVED the k6 Musicaa demo at GrafanaCON. So much so that I’m trying to replicate it on my side however I’m hitting a blocker and wondering if anyone can give me guidance.

If it helps I’m on Linux, Pop!_OS 22.04 with Chrome installed.

  1. I built a bundle with xk6 build --with github.com/grafana/xk6-browser
  2. Created basic test.js script using the provided examples:

import launcher from 'k6/x/browser'; export default function () { const browser = launcher.launch('chromium', { headless: false }); const context = browser.newContext(); const page = context.newPage(); page.goto('http://whatsmyuseragent.org/'); page.close(); browser.close(); }

However when I try running this binary with ./k6 run test.js
I get:

ERRO[0000] cannot allocate browser: cannot start browser: does not exist: at reflect.methodValueCall (native)

I have chromium installed and on my path so I’m not sure what this error is trying to tell me.

Hi there!

I’m not familiar with Pop!_OS, but from what I understand it uses Flatpak by default. Did you install Chromium via Flatpak?

If so, that might be the issue. We only officially support browsers running natively, and not under any sort of container layer like Flatpak, snapd or Docker.

Try installing Chromium as a native APT package. This Reddit thread might be helpful.

If you didn’t use Flatpak, then we might need to troubleshoot further. What does ls -al $(which chromium) and echo $PATH output?

1 Like

Oh dang you’re right - Chrome was installed via Flatpack. I’ll try installing Chromium as you suggested. Thanks for the suggestion imiric!

Not sure this is the right PPA but here’s what worked for me:

sudo add-apt-repository ppa:chromium-team/stable
sudo apt-install chromium-browser

Let me share my solution here, maybe this helps also others :slight_smile:

I have followed this page Download Chromium to this gh site GitHub - scheib/chromium-latest-linux: Scripts to download and run the latest Linux build of Chromium. A substitute for Chrome Canary on Linux. .

After git cloning the repo and run ./update-and-run.sh was the latest chromium downloaded into latest dir.

alex@alex-tuxedoinfinitybooks1517gen7 on 27/09/2024 at 22:14:49_CEST /datadisk/git-repos/chromium-latest-linux $ 
ls -larth /datadisk/git-repos/chromium-latest-linux
total 56K
drwxr-xr-x 159 alex autologin  12K Sep 27 22:14 ..
-rwxrwxr-x   1 alex alex       694 Sep 27 22:14 update.sh
-rwxrwxr-x   1 alex alex        54 Sep 27 22:14 update-and-run.sh
-rwxrwxr-x   1 alex alex       119 Sep 27 22:14 run.sh
-rw-rw-r--   1 alex alex        88 Sep 27 22:14 README.md
-rw-rw-r--   1 alex alex       12K Sep 27 22:14 LICENSE
drwxrwxr-x   8 alex alex      4,0K Sep 27 22:14 .git
drwxrwxr-x   3 alex alex      4,0K Sep 27 22:14 1361320
lrwxrwxrwx   1 alex alex        21 Sep 27 22:14 latest -> 1361320/chrome-linux/
drwxrwxr-x   5 alex alex      4,0K Sep 27 22:14 .
drwx------  32 alex alex      4,0K Sep 27 22:14 user-data-dir

Now was it possible to cal k6 with this the Environment variables as documented /docs/k6/latest/using-k6-browser/options/#environment-variable-options

The browser-test.js is the content of /docs/k6/latest/using-k6-browser/running-browser-tests/#run-a-test

alex@alex-tuxedoinfinitybooks1517gen7 on 27/09/2024 at 22:16:08_CEST /datadisk/git-repos/learn-k6 $ 
K6_BROWSER_HEADLESS=false \
K6_BROWSER_EXECUTABLE_PATH="/datadisk/git-repos/chromium-latest-linux/latest/chrome" \
K6_BROWSER_ARGS="--user-data-dir=/datadisk/git-repos/chromium-latest-linux/user-data-dir" \
k6 run browser-test.js 

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: browser-test.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * ui: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)


     ✓ header

     browser_data_received.......: 5.8 kB  3.2 kB/s
     browser_data_sent...........: 2.3 kB  1.3 kB/s
     browser_http_req_duration...: avg=223.91ms min=1.55ms   med=132.75ms max=462.01ms p(90)=435.8ms  p(95)=448.91ms
     browser_http_req_failed.....: 0.00%   ✓ 0        ✗ 5  
     browser_web_vital_cls.......: avg=0        min=0        med=0        max=0        p(90)=0        p(95)=0       
     browser_web_vital_fcp.......: avg=564.65ms min=549.3ms  med=564.65ms max=580ms    p(90)=576.93ms p(95)=578.46ms
     browser_web_vital_fid.......: avg=299.99µs min=299.99µs med=299.99µs max=299.99µs p(90)=299.99µs p(95)=299.99µs
     browser_web_vital_inp.......: avg=72ms     min=72ms     med=72ms     max=72ms     p(90)=72ms     p(95)=72ms    
     browser_web_vital_lcp.......: avg=580ms    min=580ms    med=580ms    max=580ms    p(90)=580ms    p(95)=580ms   
     browser_web_vital_ttfb......: avg=495.1ms  min=457.8ms  med=495.1ms  max=532.39ms p(90)=524.93ms p(95)=528.66ms
   ✓ checks......................: 100.00% ✓ 1        ✗ 0  
     data_received...............: 0 B     0 B/s
     data_sent...................: 0 B     0 B/s
     iteration_duration..........: avg=1.56s    min=1.56s    med=1.56s    max=1.56s    p(90)=1.56s    p(95)=1.56s   
     iterations..................: 1       0.550191/s
     vus.........................: 1       min=1      max=1
     vus_max.....................: 1       min=1      max=1


running (00m01.8s), 0/1 VUs, 1 complete and 0 interrupted iterations
ui   ✓ [======================================] 1 VUs  00m01.8s/10m0s  1/1 shared iters

Hth
Alex

1 Like