Beacon Sample

Available in Chrome 39+ | View on GitHub | Browse Samples


Beacon lets you asynchronously transfer small HTTP data from the User Agent to a web server. It can be used e.g. to send analytics or diagnostics code without delaying the page's unload or affecting the performance of the next navigation.

The sample below sends a beacon to a sample server at on unload. Close this page and visit the PutsReq inspect page to see if the beacon data was received.

JavaScript Snippet

if ('sendBeacon' in navigator) {
  window.addEventListener('pagehide', function() {
      'Sent by a beacon!');
  }, false);