skip to Main Content

I have a web application that talks to a connected device from Chrome and which for specific reasons needs to be tested from within a Docker container. The device has two USB endpoints, one of which is an emulated serial device.

The various settings necessary for direct HW and UI access from inside a container are there, whereby I mean that if I launch Chromium manually from inside the official Playwright Docker image, I can use said webapp to flash the device and then connect to it over its TTY connection. In both cases, Chromium first pops up a dialog that I have to interact with (by selecting the device from a list) to grant the browser access to the relevant hardware.

However, if I run a Playwright test that attempts to automate the process, the second dialog does not list any TTY devices at all, causing the test to fail. The test is very simple and only simulates clicks on the webapp’s buttons, which is why I don’t believe the test itself has anything to do with this behavior.

I suspect there is some difference between how I am launching Chromium and how Playwright is doing it, but I haven’t been able to find a way to compare the two. When running Chrome manually, I have to include the --no-sandbox command-line option. However, I have checked on chrome://sandbox and Playwright appears to be using this setting as well, probably among others.

Is there any way to see what command-line options Playwright is using to launch Chromium?

2

Answers


  1. Chosen as BEST ANSWER

    It turns out I was approaching the problem from the wrong direction.

    On Linux it is fairly easy to get the command-line used to launch any running process:

    ps -aux
    

    Find the chrome process with the lowest PID and bam, that's it.

    It turns out it's

    chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-YHRWJD --remote-debugging-pipe --no-startup-window
    

  2. Yes, you can use the Playwright API to retrieve the command-line arguments used by Playwright to launch Chromium. The browserType.launch() method in Playwright returns a Browser instance, which has a process() method that provides information about the browser process, including the command-line arguments.

    Here’s an example of how you can retrieve the command-line options used by Playwright to launch Chromium:

    const { chromium } = require('playwright');
    
    async function getChromiumCommandArgs() {
      const browser = await chromium.launch();
      const browserProcess = browser.process();
      const commandArgs = browserProcess.spawnargs.slice(2); // Exclude node and script paths
    
      console.log('Chromium command-line arguments:', commandArgs);
    
      await browser.close();
    }
    
    getChromiumCommandArgs();
    

    When you run this code, it will launch Chromium using Playwright, retrieve the command-line arguments used for launching, and print them for compare.

    Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search