如何使用Chrome无头模式延迟捕获DOM



我在Windows 10上的Chrome 70中使用以下命令行:

chrome--headless--启用日志记录--转储domhttp://localhost/test.html

该页面包含以下内容:

<!DOCTYPE html>
<html>
<head>
<script>
setTimeout(function () { document.write("This is a test"); }, 10);
</script>
</head>
<body>
Content to replace.
</body>
</html>

请注意,我有一个模拟异步进程的脚本来查询数据。超时设置为10ms时,Chrome命令行的页面输出为:

<html><head></head><body>This is a test</body></head></html>

当我将超时时间增加到50或更多时,输出是原始页面。

如何告诉Chrome等待异步进程完成,以及何时完成?

您可以使用--virtual时间预算参数,该参数允许您指定愿意等待的时间(以毫秒为单位(。

chrome --headless --enable-logging --dump-dom --virtual-time-budget=10000 http://localhost/test.html

最新更新