使用 launchOptions 设置浏览器启动配置并将对象传递给浏览器实例。
var launchOptions = new BrowserTypeLaunchOptions
{
Headless = false,
Args = new[] { "--disable-web-security" }
};
browser = await browserType.LaunchAsync(launchOptions);
从 playwright.config.ts 使用以下配置,
const config: PlaywrightTestConfig = {
projects: [
{
name: 'chromium',
use: {
launchOptions: {
args: ['--disable-web-security'],
}
},
}
]
}