Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug(authHeaders): Auth headers ignored for sendOnClose #399

Closed
EandrewJones opened this issue Jan 17, 2024 · 2 comments
Closed

Bug(authHeaders): Auth headers ignored for sendOnClose #399

EandrewJones opened this issue Jan 17, 2024 · 2 comments
Assignees
Labels
bug Good First Issue Stuff for folks new to project

Comments

@EandrewJones
Copy link
Contributor

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 and SO suggestions.

@EandrewJones EandrewJones changed the title Auth headers ignored for sendOnClose Bug(authHeaders): Auth headers ignored for sendOnClose May 7, 2024
@EandrewJones EandrewJones added bug Good First Issue Stuff for folks new to project labels May 7, 2024
@EandrewJones
Copy link
Contributor Author

Assigned to @rc10house

@rc10house
Copy link
Contributor

Created Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Good First Issue Stuff for folks new to project
Projects
None yet
Development

No branches or pull requests

2 participants