0

We are using websocket to send user activity events such as clicks,mousemove,scroll,input and ... Along with it, we send html dom snapshot too. The average size of html snapshot is around ~300 kb. In some cases, the html snapshot has not reaching our servers. Below are the few scenarios.

  1. User only just stays a few seconds and closes the window.

  2. While in slow network

We tried sending remaining events on beforeunload event that is also not working.

Is there anyway to solve this problem?

kannanrbk
  • 6,964
  • 13
  • 53
  • 94
  • Reducing the amount of data you send using a quick deflate routine will help in all situations. something [like this old one i've used since back in the day](http://danml.com/js/compression.js), which can chomp repetitive key-names in HTML or JSON down into 1/10th the original size. – dandavis Apr 17 '17 at 08:02
  • Why are you worrying about what happens when the user closes the page? When they have closed your page, it's game over, and that's the way the Web works. You can't just queue up background processing tasks on users' browser agent when they have indicated that they're leaving your website. Looks to me like something that should be rewritten into a standalone application where the user is explicitly informed of what they're getting into. With sending users events and other fingerprinting information (like DOM, which may or may not be augmented with users own scripts) and all. – Armen Michaeli Apr 17 '17 at 11:13

2 Answers2

0

As far as I know there is no way to solve this.

You can use the beforeunload event to gain some time, but you cannot block until the data is sent asynchronously.

Community
  • 1
  • 1
vtortola
  • 34,709
  • 29
  • 161
  • 263
0

If the user will visit again, you could use localStorage to save the data and retransmit when they come back.

Curt Evans
  • 346
  • 2
  • 4