Chrome(和其他浏览器)如何处理ASETSETIMEOUT”当隐藏浏览器选项卡被隐藏和不活动时,设置为高于1000毫秒?

发布于 2025-01-22 11:58:37 字数 1216 浏览 0 评论 0原文

我正在通过外部供应商为客户保留的网站上调试一些登录/注销问题,并希望标题可以解释内容,但更多详细信息如下。

据我了解,在Chrome中隐藏的选项卡中运行的任何JavaScript都会改变任何settimeout的值,以保持1000毫秒,以保持整体系统性能而不是浪费资源。如在此站点上说明了

“浏览器就是这样做的。对于无活动的选项卡,无论代码中指定的原始延迟如何,它们都会自动防风计时器每1秒运行一次。 例如,如果代码最初使用的setInterval()每50 ms运行一些代码,一旦将应用程序移至背景选项卡,则该间隔会自动变为1000 ms(1秒)。”

对于settimeout值,该值的设置低于1,000毫秒(例如50毫秒等),这绝对是有道理的。但是,值高于1,000毫秒呢?

Chrome是否将settimeout值设置为1,000毫秒,即使900,000毫秒(又名:900秒,又名:15分钟)显然高于此?

这是供应商网页中的一部分代码,我认为正在引起我试图协助调试的问题。当它在隐藏的选项卡中时,它没有完成工作。

function keepSessionAlive() {
    if (externalAdminWindow && externalAdminWindow.closed) {
        externalAdminWindow = null;
    }
    if (externalFGWindow && externalFGWindow.closed) {
        externalFGWindow = null;
    }
    if (externalAdminWindow || externalFGWindow) {
        $find("ctl00_RadAjaxManager1").ajaxRequest("KeepAlive");
        setTimeout(function() {
            keepSessionAlive();
        }, 900000);
    }
}

I’m debugging some login/logout issues on a site maintained by an outside vendor for a client and hopefully the title explains things, but more details are below.

As I understand it, any JavaScript running in a hidden tab in Chrome will alter the value of any setTimeout to be 1000 milliseconds to maintain overall system performance and not waste resources. As explained on this site:

“Browsers do exactly this. For inactive tabs, they automatically throttle timers to run every 1 second, regardless of the original delay specified in the code. For example, if the code originally used setInterval() to run some code every 50 ms, once the application is moved to a background tab, the interval automatically becomes 1000 ms (1 second).”

That definitely makes sense in the case of a setTimeout value that is set lower than 1,000 milliseconds like 50 milliseconds and such. But what about values higher than 1,000 milliseconds?

Will Chrome set the setTimeout value to 1,000 milliseconds even though 900,000 milliseconds (aka: 900 seconds, aka: 15 minutes) is clearly higher than that?

Here is a chunk of code from the vendor’s web page I believe is causing issues I am attempting to assist in debugging. It doesn’t do its job when it is in a hidden tab.

function keepSessionAlive() {
    if (externalAdminWindow && externalAdminWindow.closed) {
        externalAdminWindow = null;
    }
    if (externalFGWindow && externalFGWindow.closed) {
        externalFGWindow = null;
    }
    if (externalAdminWindow || externalFGWindow) {
        $find("ctl00_RadAjaxManager1").ajaxRequest("KeepAlive");
        setTimeout(function() {
            keepSessionAlive();
        }, 900000);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆头 2025-01-29 11:58:37

大多数浏览器油门无活动标签中的超时。这意味着所有settimeout的s至少将具有1000毫秒的超时。一切都比预期工作的时间更长。因此,回答您的问题,不应影响15分钟的超时。

查看settimeout's intactive tabs中的超时 https://develoverer.mozilla.org/en-en-us/docs/web/api/settime/settime/time-time-timeout#time-time-timeoutsout_in_inactive_tabs

Most browsers throttle timeouts in inactive tabs. It means that all setTimeout's will have a minimum of 1000ms timeout. Everything longer than that should work as expected. So, answering your question, 15min timeout should not be affected.

Check out setTimeout's Timeouts in inactive tabs section on MDN: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#timeouts_in_inactive_tabs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文