I'm trying to test in Chrome so I can run Google Lighthouse directly in my test suite. When I try to login I get a page from Google saying "The browser or app may not be secure" after I submit my email address.
I've seen a few other posts with this issue and tried their suggestions but I can't seem to work around it, can't anybody help?
This is how I set up my browser in playwright.config.ts
{
name: 'Chrome - Desktop',
use: {
...devices['Desktop Chrome'],
browserType: 'chromium',
launchOptions: {
ignoreHTTPSErrors: true,
},
chromium: {
args: ['--disable-blink-features=AutomationControlled'],
},
} as LaunchOptions,
},
You must also have a recent user-agent
So, along with the arg --disable-blink-features=AutomationControlled
you can add these
const { chromium } = require('playwright');
const browser = await chromium.launch({
headless: false,
args: [
'--disable-blink-features=AutomationControlled',
'--no-sandbox', // May help in some environments
'--disable-web-security', // Not recommended for production use
'--disable-infobars', // Prevent infobars
'--disable-extensions', // Disable extensions
'--start-maximized', // Start maximized
'--window-size=1280,720' // Set a specific window size
]
});
and make sure you set in your context one of the latest user-agent, use the npm package "user-agents" (https://www.npmjs.com/package/user-agents) to generate one that fits the browser and the os that you use
const ua = require('user-agents');
const userAgent = new ua({
platform: 'MacIntel', // 'Win32', 'Linux ...'
deviceCategory: 'desktop', // 'mobile', 'tablet'
});
const context = await browser.newContext({
userAgent: userAgent.toString(),
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 1,
});
const page = await context.newPage();
in my case, after updating the user-agent to a newer one it finally worked, even if my ua was not that old
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With