我想有条件地基于puppeteer中的headless
config属性执行一些代码(在.launch
函数中传递)。
例如:当我使用.type
函数时,如果它与headless: true
一起运行,我将不需要任何delay
。否则,添加一些{ delay: 200 }
。
如何从配置中检索headless
值?
答案 0 :(得分:0)
编辑 (感谢@AndreyLushnikov评论)
您可以通过检查browser.process() spawnargs
中是否有--headless
启用(或不启用)Chromium的开关来检查操纵up是否在运行时(无)无头状态:
const headless = browser.process().spawnargs.includes("--headless") ? true : false;
console.log("Headless? " + headless);
答案 1 :(得分:0)
使用最新的操纵up版本(1.7.0),这就是我检索配置的方式:
const client = await page.target().createCDPSession();
const response = await client.send('Browser.getBrowserCommandLine');
page.headless = response.arguments.includes('--headless');
有关更多信息,请参见this github issue