Navigator.sendBeacon() data size limits Navigator.sendBeacon() data size limits google-chrome google-chrome

Navigator.sendBeacon() data size limits


The maximum size, if set, will be up to the user agent (browser, or whatever).

See http://www.w3.org/TR/beacon/#sec-sendBeacon-method

You could easily create a test for the data size limit in your web page by creating strings of variable length N (starting with an arbitrarily high value for N, and using binary search), and check the return value of sendBeacon (per the spec, sendBeacon returns false when the user agent data limit is exceeded).

For example, I used this method to confirm that in Chrome 40 on Windows 7 the limit is 65536 (2^16).

Example code (without the binary search for n):

var url = 'http://jsfiddle.net?sendbeacon';var n = 65536; // sendBeacon limit for Chrome v40 on Windows (2^16)// this method courtesy of http://stackoverflow.com/questions/14343844/create-a-string-of-variable-length-filled-with-a-repeated-charactervar data = new Array(n+1).join('X'); // generate string of length nif(!navigator.sendBeacon(url, data)){   alert('data limit reached');}


Answering to Zbun's question in comment:

In short, both the total byte size of sendBeacon() request queues as well as payload size of a single sendBeacon() request both have limits.

As was mentioned in nothingisnecessary's answer, the W3C spec says:

The user agent MUST initiate a fetch with keepalive flag set, which restricts the amount of data that can be queued by such requests to ensure that beacon requests are able to complete quickly and in a timely manner.

This still leaves the actual byte size limit up to each implementation, which is typically 64KB for most browsers at the moment.

Also in a related GitHub issue, Enforce payload limits via Fetch API #39, it is mentioned that the byte size of the payload in transmission is counted and has similar restriction. You can take a look at Chromium's test file to see that 64KB is the limit for Chromium and the exact same behavior as you pointed out (subsequent requests after exceeding the limit) is appropriate.

https://chromium.googlesource.com/chromium/src/+/c1a211aa583ade023aca652e9493c01603623aa3/third_party/WebKit/LayoutTests/http/tests/sendbeacon/beacon-allowance-limit.html