chrome浏览器的默认超时时间

浏览器的默认值是5分钟

相关代码地址如下:https://source.chromium.org/chromium/chromium/src/+/main:net/socket/client_socket_pool.cc;l=25

测试代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button id="queryBtn">query</button>
    <time id="time"></time>
    <script>
        const ajax = (url = '/api/timeout') => {
            const xhr = new XMLHttpRequest();
            //设置xhr请求的超时时间
            xhr.timeout = 60 * 5 * 1000;
            xhr.responseType = "text";
            xhr.open('GET', url, true);
            xhr.onload = function(e) { 
                if(this.status == 200 || this.status == 304){
                    console.log('请求完毕')
                    if(loopId) {
                        clearInterval(loopId)
                    }
                }
                console.log(e)
            }
            xhr.send()
        }
        const queryBtn = document.querySelector('#queryBtn')
        const time = document.querySelector('#time')
        loopId = null
        queryBtn.addEventListener('click', (event) => {
            ajax()
            const startTime = new Date()
            loopId = setInterval(() => {
                const s = parseInt((new Date() - startTime) / 1000)
                time.innerHTML = s + ' s'
            }, 500)
        })
    </script>
</body>
</html>

修改 Chrome 的超时设置

谷歌浏览器不会让用户更改 Chrome 的超时设置。


下面操作未经过测试,感兴趣的可以试试看

通过编辑注册表来处理这个问题。我认为注册表不仅会影响 IE,还会影响 Windows 10 中的 Chrome。我尝试延长超时时间。然后我可以延长它,在我的情况下,最大超时时间约为 7 小时。

单击“开始”或按Win-R以获取“运行”框,键入regedit,然后单击“确定”。

在注册表中找到并单击以下项:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings

在编辑菜单上,指向新建,然后单击 DWORD 值。

键入KeepAliveTimeout,然后按 Enter。

在编辑菜单上,单击修改。

键入适当的超时值(以毫秒为单位),然后单击“确定”。例如,要将超时值设置为两分钟,请键入120000

创建另一个 DWORD 值ServerInfoTimeout并将其设置为相同的值。

重启机器。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值