Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document.referrer is set on cy.visit(...) #4295

JustTB opened this issue May 23, 2019 · 1 comment


2 participants
Copy link

commented May 23, 2019

Current behavior:

document.referrer is set to cypress test url when I use cy.visit(...)

Desired behavior:

document.referrer is an empty string

Steps to reproduce: (app code and test code)


jscode on the page:



3.3.1 cypress (chromium 73 and electron 61)
Kubuntu 18.04


This comment has been minimized.

Copy link

commented May 24, 2019

Can confirm. The left side is visiting the url in normal Chrome, the right side is visiting the url within Cypress.

Screen Shot 2019-05-24 at 11 03 10 AM

This is due to Cypress rendering the application under test within an iframe.

This property is readonly, but it does look as if Cypress can override what it returns like so:

Object.defineProperty(document, 'referrer', { get () { return ''; } })

I don't think there should be any instances during cy.visit() where this shouldn't return an empty string, even in the case of 3xx redirects, this will be maintained by the browser appropriately.

I would also likely only make this change from Cypress if the modifyObstructiveCode is true.

Workaround Today

You could detect if you application is running from within Cypress and set the referrer to an empty string in this case.

if (window.Cypress) {
  // we are running in Cypress
  Object.defineProperty(document, 'referrer', { get () { return ''; } })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.