question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: ability to set xmlHttpRequest.withCredentials

See original GitHub issue

Do you want to request a feature or report a bug? Feature

What is the current behavior? xmlHttpRequest.withCredentials takes on the default value (false) and I can’t use Pusher auth calls to set cookies.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.

Example code:

const pusher = new Pusher(REACT_APP_PUSHER_KEY, {
  cluster: REACT_APP_PUSHER_CLUSTER,
  authEndpoint: `${REACT_APP_BACKEND_HOST}/pusher/auth/web`,
  auth: {
    headers: {},
    params: {
        // [irrelevant]
    },
  },
});

pusher.connect();

REACT_APP_BACKEND_HOST is potentially on a different origin. When the backend sends

Set-Cookie: connect.sid=s%3AKjPBOeBYzc705H7vq4qnkSXPHV2zF1qi.x7N8w9e2sCc0Z2hQHeWaBy9b73M04gI0qi0WkY%2F%2BbYc; Path=/; Expires=Tue, 22 Sep 2020 03:11:57 GMT; HttpOnly

The cookie is not persisted in the browser.

What is the expected behavior? Expose the internal xmlHttpRequest config so I can set withCredentials = true. I’m using this in the Web runtime.

Which versions of Pusher, and which browsers / OS are affected by this issue? Did this work in previous versions of Pusher? If so, which? This hasn’t been an option in the past to my knowledge. I’m using Pusher JS 6.0.3.

I’ve seen the workarounds suggested in https://github.com/pusher/pusher-js/issues/62, but I’d rather not have to keep up with private API changes and I think this is a widely applicable use case! 🙂

Thank you so much!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
jeffstephenscommented, Jul 16, 2020

@leesio I think that makes perfect sense. withCredentials is all I need and it might make it easier with your cross-platform solutions!

We can kind of already supply our own which is what I’m doing for now:

Pusher.Runtime.createXHR = function () {
  var xhr = new XMLHttpRequest();
  xhr.withCredentials = true;
  return xhr;
};

But a first-class option would be great. Thank you!

2reactions
mabasiccommented, Aug 21, 2020

Just stumbled upon this issue myself. Having includeCredentials: true, would be really helpful. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make XMLHttpRequest cross-domain withCredentials ...
I've written an article with a complete CORS setup. ... It's easiest just to copy the Origin header of the request to this...
Read more >
Cross-origin XMLHTTPRequest.withCredentials = false ...
withCredentials to false when making a cross-origin request and it requires further headers to be set in CORS to allow with credentials. Given...
Read more >
XMLHttpRequest.withCredentials - Web APIs
The XMLHttpRequest.withCredentials property is a Boolean that indicates whether or not cross-site Access-Control requests should be made using credentials ...
Read more >
How to send a cookie with a cross-origin XMLHttpRequest ...
The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. So if your content script code ...
Read more >
Access-Control-Allow-Credentials HTTP Header - Holistic SEO
XMLHttpRequest can be used to have the Request's credentials mode to “include”. To grant permission, the XMLHttpRequest's “withCredentials” ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found