← Back to Discord Forum

Is it possible to change browser arguments in the middle of the test?

guitarsngamesposted in #help-playwright
Open in Discord

Hi team! I am using **Python **+ Playwright. And I use fake audio input in my tests with the "--use-file-for-fake-audio-capture" argument. What I am interested right now? Whether it is possible to launch chromium with that argument, use first audio file as input, then I do some logic in my app, next I want second file to be played through the fake mic, but I don't want to close the browser, I want to continue in the same page. Anyone has any similar experience? Is it possible? How to do that?

This thread is trying to answer question "Is it possible to change browser arguments in the middle of a test using Python and Playwright, specifically to use different audio files as input without closing the browser?"

5 replies

Hi, I have no experience with this, but was looking around out of curiosity. From what I see, the Chromium support for this is limited/pretty basic. It just plays that one file, and when done, it loops to the start. At least that's what's suggested by this (fixed) issue: https://bugs.chromium.org/p/chromium/issues/detail?id=618215

I suppose overwriting/appending the audio file is not possible/not helping?

Maybe instead of using Chromium's fake-audio-capture, you can create a virtual audio device in Linux?

It may be worth creating a GitHub issue too, perhaps the Playwright dev team has a better idea.

I suppose overwriting/appending the audio file is not possible/not helping? That's an interesting idea! Thx man! I'll check it out.

I suppose overwriting/appending the audio file is not possible/not helping? Tried to rename audio files during the test, but it didn't work out. Seems like the file passed together with arguments just uploaded and played in a loop, so it is inside of the browser and local files are not considered.

Also asked on Facebook, but no answers/advices there.


Sure, you can modify browser arguments mid-test with Playwright without closing the browser or leaving the current page. Here's how:

First, create an instance of the Browser class from the playwright package. This class represents a single browser instance and provides methods for launching new browser contexts.

const { chromium } = require('playwright');
const browser = await chromium.launch();
const context = await browser.newContext({
  args: ['--no-sandbox', '--disable-setuid-sandbox'],

In the above example, we've launched a new context with two arguments (--no-sandbox and --disable-setuid-sandbox).

If you want to change these arguments mid-test, create a new context with updated arguments and then create a new page within that context.

const updatedContext = await browser.newContext({
  args: ['--disable-gpu', '--lang=en-US'],
const page = await updatedContext.newPage();
await page.goto('https://ray.run');

In this example, we've created another instance of BrowserContext called updatedContext, passing different set of command-line arguments (--disable-gpu, --lang=en-US). Then, we create a new page within this updated context using newPage() method.

Remember, changing browser arguments mid-test may affect the behavior of the browser and the loaded web pages. Some arguments may require a browser restart to take effect, while others can be modified dynamically. So, consider which arguments can be safely changed during runtime and test accordingly.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.