Skip to content

Instantly share code, notes, and snippets.

@jakub-g
Last active February 6, 2020 07:10
Show Gist options
  • Save jakub-g/aeae2c4f8f82b4d4018423c9f6d84f28 to your computer and use it in GitHub Desktop.
Save jakub-g/aeae2c4f8f82b4d4018423c9f6d84f28 to your computer and use it in GitHub Desktop.
navigator.sendBeacon brain dump -- many not so great points

navigator.sendBeacon(url, data)

The data parameter is an ArrayBufferView, Blob, DOMString, or FormData object containing the data to be transmitted.

  • no plain old key-value JS object :| serialization of an object to a string up to the developer

  • always POST, not possible to send GET :|

  • when DOMString passed, the request type is Content-Type: text/plain, hence expressjs middlewares that read postdata won't process it :/ need to write custom middleware

@jakub-g
Copy link
Author

jakub-g commented Feb 6, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment