-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Current behavior
I get this error in about half of all attempts:
In console:
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'postMessage')
at PrimaryOriginCommunicator.toSource (cypress_runner.js:169306:12)
at PrimaryOriginCommunicator. (index-f74a2fdb.js:146501:43)
While Cypress states that the "error originated from your application code, not from Cypress", it actually does originate from Cypress, here:

Desired behavior
There should be no error. Also it's misleading that the UI says the error doesn't originate from Cypress when it does.
Test code to reproduce
I couldn't make a reproduction in time and I don't want to publish my company's internal url. However, the test code is very simple:
cy.visit('http://localhost:4200/'); // Used to set the global origin to localhost instead of the login provider, which would otherwise be the first visit. Not sure if relevant: localhost would js-redirect to company home page if given enough time.
cy.visit('https://sso-provider.example.com/login');
// Error
cy.origin('https://sso-provider.example.com', { args: loginData }, ({ user, password }) => {
// ...
});As you can see on my first screenshot, a XHR request of the first website is still marked as pending, so I guess the ending event was the one that couldn't get through anymore.
Cypress Version
13.6.2
Node version
v18.17.0
Operating System
Windows 11 22H2
Debug Logs
No response
Other
As a workaround, a global event listener seems to work:
Cypress.on('uncaught:exception', (error: Error) => {
// returning false here prevents Cypress from failing the test
console.error('Caught error', error);
if (error.stack?.includes('PrimaryOriginCommunicator.toSource')) {
return false;
}
return true;
});