title: How can I check if a user closed a specific tab/window in Flask?
body: <p>I am running a server that allows users to detect motion via their webcam. The motion detector window/URL streams a live feed and I want to detect when the stream/motion detection was cut off if the user closes the window/tab directly instead of clicking the stop button.</p>
  
  <p>I tried searching for a solution online but could not find one.</p>
  
  <p>Here's the code for the route in the flask app</p>
  
  <pre><code>@app.route('/camera')
  @login_required
  def camera():
      return Response(get_frame(), mimetype='multipart/x-mixed-replace; boundary=frame')
  </code></pre>
  
  <p>The 'get_frame()' passed in the <em>Response</em> above does not have a <em>return</em> statement, it uses <em>yield</em> instead to provide the images from webcam as a motion picture.</p>
  
  <pre><code>def get_frame():
      ....
      ....
      yield (b'--frame\r\n'
          b'Content-Type: text/plain\r\n\r\n' + imageData + b'\r\n')
  </code></pre>
  
  <p>I want to detect it to create timestamps for when the motion detector was started and when it stopped.</p>