I'm sending queries to my server using native fetch from Google Chrome or Mozilla Firefox:
fetch(url, {
method: 'POST',
body: formData,
credentials: 'include'
})
I set up a server to send a response after 3 minutes and realized that both browsers only wait 2 minutes. Firefox resend the request once more before failing.
Is there a way to define a timeout bigger than 2 minutes (say infinite)?
By default a fetch() request timeouts at the time setup by the browser. In Chrome, for example, this setting equals 300 seconds. That's way longer than a user would expect for a simple network request to complete. A good approach when making network requests is to configure a request timeout of about 8 - 10 seconds.
To set request timeout with Fetch API, we can use the AbortController constructor. const controller = new AbortController(); const timeoutId = setTimeout(() => controller. abort(), 5000); const req = async () => { const response = await fetch(url, { signal: controller.
The default timeout is 10 seconds. The minimum is 1 millisecond and the maximum is 120 seconds. If the callout is timing out, please try and increase the timeout on the HTTP request to avoid that.
For the API as a whole, you set a timeout of 30 seconds. For /resource1 , you set a 10-second timeout for the resource as a whole, but you also set a 40-second timeout for the POST operation and a 20-second timeout for the GET operation.
As far as I read fetch()'s documentation on MDN, it does not have any way to specify a timeout.
You can use request or axios module if you are using nodejs. or you can use XMLHttpRequest (plain javascript in browser).
For more information HTTP request timeouts in JavaScript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With