testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Handle Chrome's Local Network Access permission prompt

Open sam-yh opened this issue 3 months ago • 21 comments

What is your Scenario?

Summary

Chrome introduced a "Local Network Access permission prompt" in Chrome 141. According to https://developer.chrome.com/blog/local-network-access this is planned for Chrome 142, but I'm seeing it right now in both Linux and Windows builds of Chrome 141.

This prompt looks like this:

Image

and blocks TestCafe tests from running until the prompt is handled. Also affects headless mode.

It would be good to have a flag or similar to auto-handle it.

I'm aware that this might not be something TestCafe can solve, but just in case, I wanted to file a request.

To observe the issue:

Just run testcafe chrome with Chrome 141 against a file like this:

fixture`Chrome141`.page`${'https://testcafe.io'}`

test('Chrome141', async t => {
    await t.wait(1000)
})

What are you suggesting?

It may depend on Chrome providing a way to disable or auto-handle the chrome://flags/#local-network-access-check flag. I don't know if there is some way Testcafe devs can provide a workaround or other way to deal with the flag / the prompt.

What alternatives have you considered?

Tried await t.setNativeDialogHandler() which doesn't work. Looked for a cli flag for chrome, couldn't find one.

Additional context

I apologize if this doesn't fit the feature request format.

sam-yh avatar Oct 02 '25 06:10 sam-yh

A workaround that depends on disabling native automation, that has worked for me:

testcafe --disable-native-automation chrome --disable-features=LocalNetworkAccessCheck  path/to/file

sam-yh avatar Oct 02 '25 08:10 sam-yh

This fixed CI runs for us, thanks!

On ubuntu (ARM64) and locally (M2 Pro Mac - not sure if the processor is relevant)

testcafe --disable-native-automation chrome:headless --disable-features=LocalNetworkAccessCheck ./tests

lloydwatkin avatar Oct 02 '25 10:10 lloydwatkin

We have the same issue, starting from this morning. Disabling native automation is not advised as far as we know, so this is not a good workaround. Is there another way to handle it? This is a real blockage at the moment.

EDIT: The above solutions does NOT work on MAC M1 PRO, the prompt keeps on popping.

gforepsly avatar Oct 03 '25 08:10 gforepsly

Using these chrome flags didn't work:

const CHROME_FLAGS = '--disable-features=PrivateNetworkAccessCheck';
const CHROME_FLAGS = '--enable-features=PrivateNetworkAccessNonSecureContextsAllowed';
const CHROME_FLAGS = '--disable-features=PermissionsPromptOnLocalNetworkAccess';

Downgrading to previous 140 version seems a temporary solution

TrinuxSG avatar Oct 03 '25 10:10 TrinuxSG

This worked for us - "browsers": "chrome --disable-features=LocalNetworkAccessChecks"

dhruvfarswan avatar Oct 06 '25 08:10 dhruvfarswan

This worked for us - "browsers": "chrome --disable-features=LocalNetworkAccessChecks"

Doesn't work on our side. Nothing above is working (neither on Linux machines, nor MAC M1 Pro). We will try to downgrade Chrome, as we are 100% blocked with this beautiful new feature from google.

EDIT: Edge works also, without any issues.

gforepsly avatar Oct 06 '25 09:10 gforepsly

Sucks! Using Edge or Firefox.

louisnelza avatar Oct 06 '25 09:10 louisnelza

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.

github-actions[bot] avatar Oct 06 '25 10:10 github-actions[bot]

Using this browser string works on MacOS and Linux (Ci/Cd pipeline): chrome:emulation:cdpPort=9222;mobile=false;orientation=horizontal;touch=false;width=1800;height=800; --headless --disable-features=LocalNetworkAccessChecks

Note the space between the ; and the browser options.

eroetman avatar Oct 07 '25 09:10 eroetman

Hello, I believe Chrome fixed this issue in the latest version - 141.0.7390.65/.66. Please try updating your Chrome version and let us know your results.

In the meantime, we are also working on the fix.

Bayheck avatar Oct 08 '25 13:10 Bayheck

@Bayheck Unfortunately no, the latest version still has issues.

pgusilic-devops avatar Oct 08 '25 14:10 pgusilic-devops

Here's a postinstall script to add the arg so you don't have to change test execution command or edit the config:

import { writeFileSync } from 'fs';
import { Project, SyntaxKind } from 'ts-morph';

// Why:

// --unsafely-disable-devtools-self-xss-warnings - this is you can copy and paste in Chrome Inspector when debugging tests.
//   https://github.com/DevExpress/testcafe/issues/8431

// --disable-features=LocalNetworkAccessChecks - disables the permission prompt for Local Network Access
//   https://github.com/DevExpress/testcafe/issues/8446
//   https://www.reddit.com/r/chrome/comments/1m354tn/comment/nhdaygs/

const targetFilePath = 'node_modules/testcafe/lib/browser/provider/built-in/dedicated/chrome/build-chrome-args.js';

/** @type {string[]} */
const argsToAdd = ['--unsafely-disable-devtools-self-xss-warnings', '--disable-features=LocalNetworkAccessChecks'];

const project = new Project();
const sourceFile = project.addSourceFileAtPath(targetFilePath);

let modified = false;

// Find all variable declarations
const variableDeclarations = sourceFile.getDescendantsOfKind(SyntaxKind.VariableDeclaration);

console.log('Patching TestCafe BS...');

for (const varDecl of variableDeclarations) {
  if (varDecl.getName() === 'defaultArgs') {
    const initializer = varDecl.getInitializer();

    if (initializer?.isKind(SyntaxKind.ArrayLiteralExpression)) {
      const elements = initializer.getElements();
      const existingArgs = elements.map((el) => el.getText().replace(/['"]/g, ''));

      for (const argToAdd of argsToAdd) {
        if (!existingArgs.includes(argToAdd)) {
          // Add the argument to the array
          initializer.addElement(`'${argToAdd}'`);
          modified = true;
          console.log(`Added '${argToAdd}' to defaultArgs`);
        } else {
          console.log(`'${argToAdd}' already exists in defaultArgs`);
        }
      }
    }

    break;
  }
}

if (modified) {
  // Save the modified file
  writeFileSync(targetFilePath, sourceFile.getFullText());
  console.log('TestCafe patched successfully!');
} else {
  console.log('Nothing to patch - all required arguments already present.');
}

Klaster1 avatar Oct 09 '25 06:10 Klaster1

Hi @pgusilic-devops,

Could you please specify the Chrome and OS versions you are using?

aleks-pro avatar Oct 10 '25 09:10 aleks-pro

For anyone struggling with this:

testcafe chrome --disable-features=LocalNetworkAccessChecks works, testcafe chrome --disable-features=LocalNetworkAccessCheck does not work

di5ko avatar Oct 16 '25 15:10 di5ko

Unfortunately it seems that with chrome version 142.0.7444.60 on arm64 the workaround testcafe chrome --disable-features=LocalNetworkAccessChecks is not working anymore.

sam-yh avatar Nov 04 '25 11:11 sam-yh

Hi @pgusilic-devops,

Could you please specify the Chrome and OS versions you are using?

@aleks-pro sorry for the long response, it was working fine for a bit and then back to the same issue. Umm the Chrome version is 142.0.7444.60 (Official Build) (x86_64)

the OS is MC OS Ventura 13.7.7

pgusilic-devops avatar Nov 04 '25 13:11 pgusilic-devops

Same here, even github actions (ubuntu-latest) are blocked due this.

pateketrueke avatar Nov 04 '25 19:11 pateketrueke

Can we change this ticket to blocker and have it expedited for faster resolvent? Thank you guys.

pgusilic-devops avatar Nov 04 '25 20:11 pgusilic-devops

Our team hit this today, for anyone else struggling through this, a lot of our early attempts were variations of testcafe chrome --disable-... --<other test cafe flags>.

Speculating that the wrong system was getting the disable flags, we were more explicit: testcafe 'chrome --disable-...' --<other testcafe flags>. In other words, make sure the entire browser command is seen by testcafe as a single thing by wrapping it in quotes. This solved our problems: in particular we found --disable-features=LocalNetworkAccessChecks to work on the default ubuntu github runners via this technique.

Hope this helps!

frenata avatar Nov 04 '25 20:11 frenata

Wow that was amazing tip.

pgusilic-devops avatar Nov 04 '25 21:11 pgusilic-devops

Can we change this ticket to blocker and have it expedited for faster resolvent?

I converted this issue to a bug. We will prepare a fix and publish a new minor release.

aleks-pro avatar Nov 12 '25 08:11 aleks-pro