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.

Cookies are not sent using fetch from electron client

See original GitHub issue

Current behavior:

When the Electron client used by cypress run performs fetch, no cookies are being sent. This seems to be a behaviour in Cypress’ Electron client handling, as I cannot seem to notice it on a raw Electon client.

Desired behavior:

Cookies should be sent. Running against a Chrome browser passes the test.

Steps to reproduce: (app code and test code)

A full minimal project can be found at https://github.com/souphan-adsk/cypress-electron-ajax-cookie

Here are key code sample:

Cypress Spec

describe('Cookie Test', function() {
	it('should send ajax cookie', function() {
		cy.visit('localhost:8880/get-cookie-test');
		cy.wait(500);
		cy.get('#ajax-cookie-value').invoke('text').then((value) => {
			expect(value).to.equal('test=OK')
		});
	});
});

Express

expressApp.get('/get-cookie-test', function(request, response) {
	console.log(request.originalUrl, 'headers.cookie =>', request.headers.cookie);
	response.cookie('test', 'OK', {
		expires: new Date(1000 * 60 * 60 * 24 + Date.now()),
	});
	response.send('<html><body>'
		+ `<p>Cookie value: <span id="cookie-string">${request.headers.cookie}</span></p>`
		+ '<p>Ajax Cookie value: <span id="ajax-cookie-value">...</span></p>'
		+ '<script type="text/javascript">'
		+ '  setTimeout(async () => {'
		+ '    let resp = await fetch("/cookie-echo");'
		+ '    document.getElementById("ajax-cookie-value").innerText = await resp.text();'
		+ '  }, 0);'
		+ '</script>'
		+ '</body></html>'
	);
});

expressApp.get('/cookie-echo', function(request, response) {
	console.log(request.originalUrl, 'headers.cookie =>', request.headers.cookie);
	response.send(request.headers.cookie);
});

Versions

Cypress 3.3.1 Electron 61 OSX

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Steakeyecommented, Jun 21, 2019

Experiencing a similar issue working for a client and our tests suddenly stopped failing in headless mode; when debugging the issue it appears as though the cookies we need - which we set earlier before all tests run - are not being passed in the request from the electron client; this is confirmed when using dev tools to look at the network traffic of the headless mode but with --headed flag passed. Everything works fine when using the Cypress UI to access the tests and run them in Chrome.

2reactions
bahmutovcommented, Aug 1, 2019

yes, and we are trying to upgrade Electron to the latest v6 in this pull request https://github.com/cypress-io/cypress/pull/4720

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending a cookie in a fetch request with Aurelia and Electron
The request is done through a http.fetch(). This request has to be done multiple times with a different cookie set by the client....
Read more >
Send cookies in Electron + React app - Coding Out Loud
In this article I discuss using cookies to make an authenticated web call to ... How could I send cookies for a domain...
Read more >
How to Pass Cookies with Fetch or Axios Requests - Sabe.io
In this post, we're going to learn how to pass cookies to the server when we make requests using the native fetch API...
Read more >
Top 5 Node-Fetch Alternatives For Making HTTP Requests
With fetch (in the browser or via Node Fetch), you can combine the await and .then ... It does not support HTTP/2 or...
Read more >
axios not sending cookie | The AI Search Engine You Control
You need to use subdomain, and let your cookie set to the domain=.app.test (whole domain). I mean, you need to make sure Laravel...
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