sendBeacon method

Provides an asynchronous and non-blocking way to transmit data to a provided URL.

Syntax

object.sendBeacon(url, data)

Parameters

url [in]

Type: string

A URL indicating where the data is to be transmitted.

data [in, optional]

Type: Blob or BufferSource or FormData or USVString

The data that is to be transmitted.

Return value

Type: boolean

Returns true if the passed data was successfully queued. false otherwise.

Standards information

Remarks

The data parameter is limited to a maximum of 65536 bytes.

Requests sent using the sendBeacon method achieve the following:

  • Don't block or compete with time-critical work.
  • May be prioritized by the browser to improve network efficiency.
  • Eliminate the need to use blocking operations to ensure delivery of beacon data.

In regards to CORS preflight requests:

  • If the payload is either application/x-www-form-urlencoded, multipart/form-data, or text/plain, no additional CORS preflight request is required because it's a simple request. This is the same as scripted form-post or XHR/fetch.
  • If the payload is a Blob and the resulting Content-Type is not a simple header, then a CORS preflight is made and the server needs to first allow such requests by returning the appropriate set of CORS headers (Access-Control-Allow-Credentials, Access-Control-Allow-Origin, Access-Control-Allow-Headers). This is the same as XHR/fetch.
Note  This method is not supported for Windows Store apps
 

See also

navigator

 

 

Show: