Using the browser's Beacon API to send data when the page unloads. This project is demonstrated in the video posted on the Request Metrics Blog, "Using the Beacon API".
In order to test the cross-origin constraints of the beacon, we need to host this project from multiple domains. Please add the following entries to your hosts
file.
127.0.0.1 example.com
127.0.0.1 beacon.requestmetrics.com
You can run everything on localhost
if you wish, but be sure to change the beacon URL in client.js.
To start the project, run npm start
and open a web browser to http://example.com:3000/
.