gpt4 book ai didi

google-chrome - Chrome CLI 的参数 --virtual-time-budget 的真正含义是什么?

转载 作者:行者123 更新时间:2023-12-02 07:19:14 27 4
gpt4 key购买 nike

我知道参数 --virtual-time-budget in the source 的文档Chromium,但我觉得我不理解它:

// If set the system waits the specified number of virtual milliseconds before
// deeming the page to be ready. For determinism virtual time does not advance
// while there are pending network fetches (i.e no timers will fire). Once all
// network fetches have completed, timers fire and if the system runs out of
// virtual time is fastforwarded so the next timer fires immediately, until the
// specified virtual time budget is exhausted.
const char kVirtualTimeBudget[] = "virtual-time-budget";

我做了一些实验,结果让我感到困惑:

# I'm on macOS; you may change this alias according to your own OS
$ alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
$ chrome --version
Google Chrome 70.0.3538.110

$ time chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/
real 0m0.912s
user 0m0.264s
sys 0m0.219s

$ time chrome --headless --disable-gpu --print-to-pdf --virtual-time-budget=10000 https://www.chromestatus.com/
real 0m2.502s
user 0m0.347s
sys 0m0.244s

$ time chrome --headless --disable-gpu --print-to-pdf --virtual-time-budget=100000 https://www.chromestatus.com/
real 0m15.432s
user 0m0.759s
sys 0m0.406s

$ time chrome --headless --disable-gpu --print-to-pdf --virtual-time-budget=1000000 https://www.chromestatus.com/
real 0m15.755s
user 0m0.755s
sys 0m0.401s

我以为 Chrome 在上述四个示例中会等待 0、10、100 和 1000 秒,然后再打印到 PDF,但实际的等待时间似乎相去甚远。我的问题是,如何让 Chrome 在将页面打印为 PDF 之前肯定等待 X 秒?我目前只考虑 Chrome CLI,并没有寻找像 Puppeteer 这样的工具。

最佳答案

我可以轻松回答您的标题问题(这解释了您的结果)。 --virtual-time-budget,说明进程等待页面加载的时间,而不是它会等待那么长时间。如果请求的结果可用(没有更多的网络请求待处理),它将立即返回结果。

返回的信息应该是正确的,除非混合了 AJAX 请求或其他 Javascript。如果是这样,您必须诉诸 Javascript/DOM 操作来解决问题。

关于google-chrome - Chrome CLI 的参数 --virtual-time-budget 的真正含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53548438/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com