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.

cy.origin() not working when the application redirects to external origin

See original GitHub issue

Current behavior

cy.origin() still not working as expected even I’ve upgraded to the new release with the related bugfixes over there. When clicking on some connect pop-up from the application it’s redirecting to google account page (external url and totally different from the base url). Trying to use cy.origin() to be able to reach out the page elements over there but the cy.origin reaching the timeout and return the error below:

Timed out retrying after 30000ms: The command was expected to run against origin https://google.com but the application is at origin https://google.com.

This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.

I’ve to inform that I’m using cy.session() for login the application by the before() hook, and the cookies preserve over there.

Also I got this error when closing the cypress runner by CMD+C :

Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:160:15)
    at writeGeneric (node:internal/stream_base_commons:151:3)
    at Socket._writeGeneric (node:net:795:11)
    at Socket._write (node:net:807:8)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at Socket.Writable.write (node:internal/streams/writable:334:10)
    at Function.log (/Users/myname/Library/Caches/Cypress/10.9.0/Cypress.app/Contents/Resources/app/node_modules/debug/src/node.js:194:24)
    at debug (/Users/myname/Library/Caches/Cypress/10.9.0/Cypress.app/Contents/Resources/app/node_modules/debug/src/common.js:113:10)
    at App.<anonymous> (/Users/myname/Library/Caches/Cypress/10.9.0/Cypress.app/Contents/Resources/app/packages/server/lib/modes/interactive.js:144:13)
    at Object.onceWrapper (node:events:646:26)
    at App.emit (node:events:526:28)
    at App.emit (node:domain:475:12)

Desired behavior

No response

Test code to reproduce

cypress configuration:

	e2e: {
		supportFile: './../myinfra/cypress/support/e2e.ts',
		downloadsFolder: './../myinfra/cypress/downloads',
		chromeWebSecurity: false,
		experimentalSourceRewriting: false,
		experimentalSessionAndOrigin: true,
		experimentalModifyObstructiveThirdPartyCode: true,
		numTestsKeptInMemory: 1,
		defaultCommandTimeout: 30000,
		requestTimeout: 30000,
		responseTimeout: 30000,
		taskTimeout: 30000,
		pageLoadTimeout: 30000,
		screenshotsFolder: './../myinfra/mochawesome-report/assets',
		screenshotOnRunFailure: true,
		reporter: './../myinfra/node_modules/mochawesome',
		reporterOptions: {
			reportDir: './../myinfra/cypress/report',
			code: false,
			charts: true,
			overwrite: false,
			html: false,
			json: true,
			embeddedScreenshots: true,
		},
		video: false,
		viewportHeight: 1080,
		viewportWidth: 1920,
		waitForAnimations: true
}

chrome 106 driver configuration:

			on('before:browser:launch', (browser, launchOptions) => {
				if (browser.name === 'chrome') {
					launchOptions.args.push(
						'--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process',
						'--disable-web-security',
						'--user-data-dir',
						'--disable-gpu',
						'--no-sandbox',
						'--start-maximized',
						'--enable-automation',
						'--safebrowsing-disable-auto-update',
						'--disable-dev-shm-usage',
						'--window-size=1920,1080'
					);
				}
				return launchOptions;
			});

Login file:

import * as loc from './locators';

export const login = (userType: string) => {
  cy.session(userType, () => {
    cy.visit('/login');
    cy.fixture('testUsers').then((user) => {
      cy.get(loc.login.emailField)
        .should('be.visible')
        .type(user[`${userType}`].email);
      cy.get(loc.login.emailField)
        .should('be.visible')
        .and('have.attr', 'value', user[`${userType}`].email);
      cy.get(loc.login.submitEmail).should('be.visible').click();
      cy.get(loc.sideNavBar.buyersPipeline).should('be.visible');
    });
  });
  cy.visit('/app');
};

Test suite file:

describe('check that pipeline works', { tags: 'smoke', defaultCommandTimeout: 30000 },() => {
	beforeEach(() => {
	  login('backofficeAdvisor');
	  cy.reload();
	});

	it('Send email to a user - is shown in the activity', () => {
	    cy.intercept('https://accounts.google.com/**').as(`loginRedirect`)
	    cy.visit('/');
	  cy.get(loc.sideNavBar.buyersPipeline).should('be.visible').click();
	  cy.get(loc.pipelineBuyer.nameColumn)
	    .eq(4)
	    .should('be.visible')
	    .click({ force: true });
	  cy.get(loc.buyerDetails.basicCard).should('be.visible');
	  cy.get(loc.buyerDetails.timelineSendEmailIcon)
	    .should('be.visible')
	    .click();
	    cy.get('div[role="dialog"]')
	        .find('button.MuiButton-root')
	        .should('be.visible')
	        .click();
	    const email = 'qa@myapp.com';
	        cy.wait(`@loginRedirect`).then(() => {
	            cy.origin('accounts.google.com', {args: [email]}, ([email]) => {
	                // @ts-ignore
	                cy.get('input#identifierId').should('be.visible').type(email);
	            })
	        })
	    cy.visit('/')
	});
});		

Cypress Version

10.9.0

Node version

14.19.1

Operating System

macOS 12.3.1

Debug Logs

`
cypress:server:socket-base automation:request get:cookies { superDomain: 'google.com' } +1s
  cypress:server:automation:cookies getting:cookies { superDomain: 'google.com' } +1s
  cypress:server:automation:cookies received get:cookies [ { name: '__stripe_sid', value: 'aaaa-1111-bbbb-2222', path: '/', domain: '.backoffice.myapp.com', secure: true, httpOnly: false, sameSite: 'strict', expiry: 1664723643 }, { name: 'NID', value: 'aaa-1111-bbbb-2222', path: '/', domain: '.google.com', secure: true, httpOnly: true, sameSite: 'no_restriction', expiry: 1680533053.010764 }, { name: '__stripe_mid', value: 'aaa-1111-bbbb-2222', path: '/', domain: '.backoffice.myapp.com', secure: true, httpOnly: false, sameSite: 'strict', expiry: 1696257843 }, { name: 'BACKOFFICE_TOKEN', value: 'aaa-1111-bbbb-2222', path: '/', domain: '.myapp.com', secure: false, httpOnly: false, sameSite: undefined, expiry: 1699280627.749086 }, { name: 'BACKOFFICE_REFRESH_TOKEN', value: 'aaa-1111-bbbb-2222', path: '/', domain: '.myapp.com', secure: false, httpOnly: false, sameSite: undefined, expiry: 1699280627.749267 }, { name: 'APP_CTX_USER_ID', value: 'aaa-1111-bbbb-2222', path: '/', domain: '.myapp.com', secure: false, httpOnly: false, sameSite: undefined, expiry: 1699280627.951294 }, { name: 'm', value: 'aaa-1111-bbbb-2222', path: '/', domain: 'm.stripe.com', secure: true, httpOnly: true, hostOnly: true, sameSite: 'no_restriction', expiry: 1699281843.547881 }, { name: 'APP_CTX_SESSION_ID', value: 'aaa-1111-bbbb-2222', path: '/', domain: '.myapp.com', secure: false, httpOnly: false, sameSite: undefined }, { name: 'randomClientString', value: 'aaa-1111-bbbb-2222', path: '/', domain: 'backoffice.myapp.com', secure: false, httpOnly: false, hostOnly: true, sameSite: undefined } ] +1ms

cypress:net-stubbing:server:intercept-request intercepting request { requestId: 'interceptedRequest346', req: { url: '/generate_204?2nUghQ' } } +5s
  cypress:net-stubbing:server:util sending event to driver { eventName: 'before:request', data: { eventId: 'event347', subscription: { eventName: 'before:request', await: false, routeId: '1664721837253-212' }, browserRequestId: undefined, requestId: 'interceptedRequest346', data: { headers: [Object], url: 'https://accounts.google.com/generate_204?2nUghQ', method: 'GET', httpVersion: '1.1', body: '' } } } +5s
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'google' } +505ms
  cypress:server:remote-states getting remote state: undefined for: https://accounts.google.com/generate_204?2nUghQ +5s
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'myapp' } +0ms
  cypress:server:remote-states getting remote state: { auth: null, origin: 'https://backoffice.myapp.com', strategy: 'http', fileServer: null, domainName: 'myapp.com', props: { port: '443', tld: 'com', domain: 'myapp' } } for: https://myapp.com +0ms
  cypress:server:stream_buffer stream buffer writeable final called +5s
  cypress:network:agent addRequest called { isHttps: true, href: 'https://accounts.google.com/generate_204?2nUghQ' } +5s
  cypress:network:agent got family { family: 4, href: 'https://accounts.google.com/generate_204?2nUghQ' } +0ms
  cypress:server:request received status code & headers on request { requestId: 'request348', statusCode: 204, headers: {} } +5s
  cypress:server:request successful response received { requestId: 'request348' } +0ms
  cypress:net-stubbing:server:intercept-response InterceptResponse { req: { url: 'https://accounts.google.com/generate_204?2nUghQ' }, request: InterceptedRequest { subscriptionsByRoute: [ [Object] ], includeBodyInAfterResponse: false, responseSent: false, onResponse: [Function (anonymous)], id: 'interceptedRequest346', req: IncomingMessage { _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 1, _maxListeners: undefined, socket: [TLSSocket], httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, rawHeaders: [Array], rawTrailers: [], aborted: false, upgrade: false, url: 'https://accounts.google.com/generate_204?2nUghQ', method: 'GET', statusCode: null, statusMessage: null, client: [TLSSocket], _consuming: false, _dumped: false, proxiedUrl: 'https://accounts.google.com/generate_204?2nUghQ', next: [Function: next], baseUrl: '', originalUrl: '/generate_204?2nUghQ', _parsedUrl: [Url], params: [Object], query: [Object], res: [ServerResponse], secret: undefined, cookies: [Object], signedCookies: [Object: null prototype] {}, _startAt: [Array], _startTime: 2022-10-02T14:44:17.713Z, _remoteAddress: '127.0.0.1', route: [Route], isAUTFrame: false, browserPreRequest: undefined, requestId: 'interceptedRequest346', body: '', [Symbol(kCapture)]: false, [Symbol(kHeaders)]: [Object], [Symbol(kHeadersCount)]: 32, [Symbol(kTrailers)]: null, [Symbol(kTrailersCount)]: 0, [Symbol(RequestTimeout)]: undefined }, res: ServerResponse { _events: [Object: null prototype], _eventsCount: 2, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: false, chunkedEncoding: false, shouldKeepAlive: true, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: true, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: null, _hasBody: true, _trailer: '', finished: false, _headerSent: false, _closed: false, socket: [TLSSocket], _header: null, _keepAliveTimeout: 5000, _onPendingData: [Function: bound updateOutgoingData], req: [IncomingMessage], _sent100: false, _expect_continue: false, locals: [Object: null prototype] {}, flush: [Function: flush], write: [Function: write], end: [Function: end], on: [Function: on], writeHead: [Function: writeHead], _startAt: undefined, _startTime: undefined, __onFinished: [Function], [Symbol(kCapture)]: false, [Symbol(kNeedDrain)]: false, [Symbol(corked)]: 0, [Symbol(kOutHeaders)]: null }, continueRequest: [Function: next], onError: [Function: onError], _onResponse: [Function: onResponse], matchingRoutes: [ [Object] ], state: { requests: [Object], routes: [Array], pendingEventHandlers: {}, reset: [Function: reset] }, socket: SocketE2E { ensureProp: [Function: ensureProp], supportsRunEvents: false, experimentalSessionAndOrigin: true, ended: false, localBus: [EventEmitter], onTestFileChange: [Function: bound ], testFilePath: '../myapp-backoffice/e2e-tests/test-files/pipeline-tests.cy.ts', onStudioTestFileChange: [Function: bound onStudioTestFileChange], removeOnStudioTestFileChange: [Function: bound removeOnStudioTestFileChange], _io: [SocketIOServer], _sendResetBrowserTabsForNextTestMessage: [AsyncFunction (anonymous)], _sendResetBrowserStateMessage: [AsyncFunction (anonymous)], _sendFocusBrowserMessage: [AsyncFunction (anonymous)], _isRunnerSocketConnected: [Function (anonymous)] }, lastEvent: 'before:request' } } +5s
  cypress:net-stubbing:server:util sending event to driver { eventName: 'response:callback', data: { eventId: 'event349', subscription: { eventName: 'response:callback', await: false, routeId: '1664721837253-212' }, browserRequestId: undefined, requestId: 'interceptedRequest346', data: { headers: [Object], url: 'https://accounts.google.com/generate_204?2nUghQ', method: null, httpVersion: '1.1', statusCode: 204, statusMessage: 'No Content', body: '' } } } +69ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'myapp' } +70ms
  cypress:server:remote-states getting remote state: { auth: null, origin: 'https://backoffice.myapp.com', strategy: 'http', fileServer: null, domainName: 'myapp.com', props: { port: '443', tld: 'com', domain: 'myapp' } } for: https://myapp.com +70ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'google' } +0ms
  cypress:server:remote-states getting primary remote state: { auth: null, origin: 'https://backoffice.myapp.com', strategy: 'http', fileServer: null, domainName: 'myapp.com', props: { port: '443', tld: 'com', domain: 'myapp' } } +0ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'google' } +0ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'myapp' } +0ms
  cypress:server:remote-states getting remote state: { auth: null, origin: 'https://backoffice.myapp.com', strategy: 'http', fileServer: null, domainName: 'myapp.com', props: { port: '443', tld: 'com', domain: 'myapp' } } for: https://myapp.com +0ms
GET /generate_204?2nUghQ 204 575.475 ms - -


### Other

**Chrome v106**


<img width="1117" alt="cy-origin-issue" src="https://user-images.githubusercontent.com/104420464/193461329-bc48bc6c-ab2f-407b-af6c-5882726c0067.png">

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
cypress-bot[bot]commented, Oct 4, 2022

The code for this is done in cypress-io/cypress#23885, but has yet to be released. We’ll update this issue and reference the changelog when it’s released.

1reaction
AtofStrykercommented, Oct 4, 2022

We likely don’t have a close base of support until 10.10.0 is out, but I am interested to see once it’s released if you are still running into the secure app issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress: How to visit a url of a different origin? - Stack Overflow
From version 9.6.0 of cypress, you can use cy.origin . ... it('checks that login page redirects to baseUrl', () => { cy.
Read more >
Web Security - Cypress Documentation
After the first cy.visit() command is issued in a test, Cypress changes its URL to match the origin of your remote application, thereby...
Read more >
Fixing Cypress cross-origin errors - Reflect.run
A step-by-step guide for avoiding cross-origin errors in Cypress tests via the cy.origin() and cy.session() commands introduced in Cypress ...
Read more >
Multi-Domain (Origin) Testing in Cypress - DEV Community ‍ ‍
Let's take a deep dive into how to use cy.origin in the real world. ... this problem is finally an easy one to...
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Modern browsers use CORS in APIs such as XMLHttpRequest or Fetch to mitigate the risks of cross-origin HTTP requests.
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