0

Though the title is decently explanatory, I'm curious as how netflix detects how a user is afk. I've looked through the code via chrome's inspect element, and found it may be done through javascript/jquery depending on the mouse position. Is there anyway anyone can verify this or if incorrect, discover the method it is determined? I'm looking to make a plugin to prevent it from pausing.

Ramity
  • 65
  • 7
  • you can set a datestamp upon mousemove or keydown on document, and optionally consider document.hasFocus as well – dandavis Oct 26 '14 at 03:34
  • http://bit.ly/1rCEUTH – 2pha Oct 26 '14 at 03:35
  • Most sites use a timeout function to detect whether a user has moved the mouse or typed within a certain amount of time, if the user hasn't the system will automatically log that user out. I've got a similar script that does exactly this. If you'd like, I'll post it as an answer so you can see how it works. –  Oct 26 '14 at 03:46

1 Answers1

2

It's hard to know for sure what Netflix exactly uses to determine if a user has left Netflix, as Netflix probably obfuscates their JavaScript code and it's illegal to reverse engineer it. But there a few possibilities:

  1. A timer that constantly calls document.hasFocus() to see if it has changed.
  2. Most web browsers (Firefox v10+, Chrome v13+, Internet Explorer v10+, Opera v12.10+, and Safari v7+) have a built-in event to check if a window/tab is active or not. Mozilla has documentation on using the visibilitychange event, including an example with a video that pauses or plays when the visibility changes.
  3. Whenever the javascript events onmousemove or onkeydown is called and the page is loaded for the first time, a variable is set to the current unix time. A timer checks this variable to see if so much time has elapsed since the event is called to see if the user has left the window. This is highly unlikely as people may watch a 2 hour movie without ever touching their mouse or keyboard.

There's also this previous question on StackOverflow which includes many different answers to the same question you asked.

Community
  • 1
  • 1
SameOldNick
  • 2,397
  • 24
  • 33