Handle Chrome's Local Network Access permission prompt
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:
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.
A workaround that depends on disabling native automation, that has worked for me:
testcafe --disable-native-automation chrome --disable-features=LocalNetworkAccessCheck path/to/file
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
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.
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
This worked for us - "browsers": "chrome --disable-features=LocalNetworkAccessChecks"
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.
Sucks! Using Edge or Firefox.
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.
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.
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 Unfortunately no, the latest version still has issues.
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.');
}
Hi @pgusilic-devops,
Could you please specify the Chrome and OS versions you are using?
For anyone struggling with this:
testcafe chrome --disable-features=LocalNetworkAccessChecks works,
testcafe chrome --disable-features=LocalNetworkAccessCheck does not work
Unfortunately it seems that with chrome version 142.0.7444.60 on arm64 the workaround testcafe chrome --disable-features=LocalNetworkAccessChecks is not working anymore.
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
Same here, even github actions (ubuntu-latest) are blocked due this.
Can we change this ticket to blocker and have it expedited for faster resolvent? Thank you guys.
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!
Wow that was amazing tip.
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.