EandrewJones opened a new issue, #399:
URL: https://github.com/apache/flagon-useralejs/issues/399

   ## Problem
   The `sendOnClose` method to flush logs before the user closes/tabs away from 
the client app does not utilize any header information, nor can it.
   
   ```
   /**
    * Attempts to flush the remaining logs when the window is closed.
    * @param  {Array} logs   Array of logs to be flushed.
    * @param  {Object} config Configuration object to be read from.
    */
   export function sendOnClose(logs, config) {
     window.addEventListener("pagehide", function () {
       if (config.on && logs.length > 0) {
         navigator.sendBeacon(config.url, JSON.stringify(logs));
         logs.splice(0); // clear log queue
       }
     });
   }
   ```
   
   ## Cause
   `navigator.sendBeacon` does not support auth headers, so this will fail if 
auth is required.
         
   ## Solution
   The alternative is to use `fetch()` with `keepalive: true` as per [official 
docs](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon#description)
 and [SO suggestions](https://stackoverflow.com/a/73062712/9263449).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org
For additional commands, e-mail: notifications-h...@flagon.apache.org

Reply via email to