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.

Unexpected error while setting cookie in Firefox

See original GitHub issue

Current behavior

We have dozens of Cypress test suites that we’ve been running for years in Chrome. I recently tried running these same tests in Firefox and Cypress is failing really early on:

13:23:56       CypressError: `cy.setCookie()` had an unexpected error setting the requested cookie in Firefox.
13:23:56  
13:23:56  > Error: An unexpected error occurred
13:23:56  
13:23:56  
13:23:56  https://on.cypress.io/setcookie
13:23:56  
13:23:56  Because this error occurred during a `before all` hook we are skipping the remaining tests in the current suite: `Topology > Export`
13:23:56  
13:23:56  Although you have test retries enabled, we do not retry tests when `before all` or `after all` hooks fail
13:23:56    handleBackendError/<@http://localhost:4001/__cypress/runner/cypress_runner.js:136770:17
13:23:56    tryCatcher@http://localhost:4001/__cypress/runner/cypress_runner.js:10798:23
13:23:56    ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromiseFromHandler@http://localhost:4001/__cypress/runner/cypress_runner.js:8733:31
13:23:56    ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromise@http://localhost:4001/__cypress/runner/cypress_runner.js:8790:18
13:23:56    ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromise0@http://localhost:4001/__cypress/runner/cypress_runner.js:8835:10
13:23:56    ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromises@http://localhost:4001/__cypress/runner/cypress_runner.js:8911:18
13:23:56    _drainQueueStep@http://localhost:4001/__cypress/runner/cypress_runner.js:5505:12
13:23:56    _drainQueue@http://localhost:4001/__cypress/runner/cypress_runner.js:5498:24
13:23:56    ../../node_modules/bluebird/js/release/async.js/</Async.prototype._drainQueues@http://localhost:4001/__cypress/runner/cypress_runner.js:5514:16
13:23:56    Async/this.drainQueues@http://localhost:4001/__cypress/runner/cypress_runner.js:5384:14
13:23:56    From Your Spec Code:
13:23:56        @http://localhost:4001/__cypress/tests?p=cypress/support/index.js:967:246652
13:23:56        runCommand/<@http://localhost:4001/__cypress/runner/cypress_runner.js:150999:15
13:23:56        tryCatcher@http://localhost:4001/__cypress/runner/cypress_runner.js:10798:23
13:23:56        ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromiseFromHandler@http://localhost:4001/__cypress/runner/cypress_runner.js:8733:31
13:23:56        ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromise@http://localhost:4001/__cypress/runner/cypress_runner.js:8790:18
13:23:56        ../../node_modules/bluebird/js/release/promise.js/</module.exports/Promise.prototype._settlePromiseCtx@http://localhost:4001/__cypress/runner/cypress_runner.js:8827:10
13:23:56        _drainQueueStep@http://localhost:4001/__cypress/runner/cypress_runner.js:5509:12
13:23:56        _drainQueue@http://localhost:4001/__cypress/runner/cypress_runner.js:5498:24
13:23:56        ../../node_modules/bluebird/js/release/async.js/</Async.prototype._drainQueues@http://localhost:4001/__cypress/runner/cypress_runner.js:5514:16
13:23:56        Async/this.drainQueues@http://localhost:4001/__cypress/runner/cypress_runner.js:5384:14
13:23:56    
13:23:56    
13:23:56    From Node.js Internals:
13:23:56      Error: An unexpected error occurred
13:23:56          (No stack trace)
13:23:56      From previous event:
13:23:56          setCookie@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:20589:20
13:23:56          invoke/<@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:20484:33
13:23:56      From previous event:
13:23:56          invoke@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:20483:20
13:23:56          connect/<@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:20499:16
13:23:56          ../../node_modules/component-emitter/index.js/Emitter.prototype.emit@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:6122:20
13:23:56          emit@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19835:15
13:23:56          emitEvent@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19580:20
13:23:56          onevent@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19567:18
13:23:56          onpacket@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19531:22
13:23:56          ../../node_modules/component-emitter/index.js/Emitter.prototype.emit@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:6122:20
13:23:56          emitReserved@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19848:15
13:23:56          ondecoded@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19115:14
13:23:56          ../../node_modules/component-emitter/index.js/Emitter.prototype.emit@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:6122:20
13:23:56          add@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:20173:23
13:23:56          ondata@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:19107:22
13:23:56          ../../node_modules/component-emitter/index.js/Emitter.prototype.emit@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:6122:20
13:23:56          onPacket@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:16987:16
13:23:56          setTransport/<@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:16796:14
13:23:56          ../../node_modules/component-emitter/index.js/Emitter.prototype.emit@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:6122:20
13:23:56          onPacket@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:17389:10
13:23:56          onData@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:17382:10
13:23:56          addEventListeners/this.ws.onmessage@moz-extension://dd4d2926-1481-4183-b953-89dd9f94b570/background.js:18379:36

I checked the debug logs and I don’t see a lot there:

2021-06-26T20:30:26.936Z cypress:server:socket-base automation:request get:cookies { domain: 'localhost' }
2021-06-26T20:30:26.937Z cypress:server:socket-base backend:request { eventName: 'reset:server:state', args: [] }
2021-06-26T20:30:26.937Z cypress:proxy:http:util:buffers resetting buffers
2021-06-26T20:30:26.937Z cypress:server:automation:cookies getting:cookies { domain: 'localhost' }
2021-06-26T20:30:26.950Z cypress:server:automation:cookies received get:cookies []
2021-06-26T20:30:26.993Z cypress:server:socket-base automation:request set:cookie { name: 'access_token', value: '', path: '/', secure: true, httpOnly: false, expiry: 2255891426, domain: 'mock', sameSite: 'no_restriction' }
2021-06-26T20:30:26.994Z cypress:server:automation:cookies set:cookie { name: 'access_token', value: '', path: '/', domain: 'mock', secure: true, httpOnly: false, sameSite: 'no_restriction', expirationDate: 2255891426, url: 'https://mock/' }

The next log message concerns taking a screenshot (because the test has been marked as failed).

Desired behavior

We should be able to set cookies in Firefox.

Test code to reproduce

  cy.setCookie('access_token', Cypress.env('accessToken'), {
    domain: getApiServerDomain(),
    sameSite: 'no_restriction',
    secure: true,
  })

Versions

Cypress 7.5.0 running on Debian 9 in a Docker environment with Firefox 88

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kaiyomacommented, Jun 28, 2021

I did some digging here today and I think I found the issue. Leaving a note in case anyone else runs into this in the future:

The problem here was related to the domain property in the setCookie options. Namely, I was trying to set an invalid domain (in this case, "mock") and that seemed to be causing the failure. I would have appreciated some more details in the error message.

0reactions
iriikoadcommented, Nov 28, 2022

Hi I’m having the same error with session when the restore:

 (No stack trace)
    setOneCookie@moz-extension://e1a58d4f-b345-4a26-b89b-f015535bd5e1/background.js:20629:18
    setCookies@moz-extension://e1a58d4f-b345-4a26-b89b-f015535bd5e1/background.js:20685:20
    ./app/background.js/connect/invoke/<@moz-extension://e1a58d4f-b345-4a26-b89b-f015535bd5e1/b
Read more comments on GitHub >

github_iconTop Results From Across the Web

An unexpected error occurred with browser.cookies.set() with ...
This call without the domain key works in Firefox. This is how the cookies API is supposed to be used. When the "domain"...
Read more >
How to Fix 'We've Detected a Problem with Your Cookie ...
How to Fix 'We've Detected a Problem with Your Cookie Settings ' In Mozilla Firefox.Google's dominance over its competitors in the aspect of ......
Read more >
spoofer.js: An unexpected error has occurred, should I be ...
I am usinng Firefox version 105.0.2 (64 bit), and noticed that for every single page I visit, in the Dev Console there is...
Read more >
Enable cookies - Microsoft Support
If you're using Windows, in the Firefox window, select Open menu · Select the Privacy tab. · In the History section under Firefox...
Read more >
How to Clear Browser Cookies to Resolve “Error 500
If you are receiving an “Error 500 – Internal Server Error” message while trying to log into Canvas, you will need to clear...
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