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

Closed
JustTB opened this issue May 23, 2019 · 4 comments · Fixed by #18658
Closed

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

JustTB opened this issue May 23, 2019 · 4 comments · Fixed by #18658
Assignees
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: bug

Comments

@JustTB
Copy link

JustTB 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)

cy.visit('https://your.test.dom/')

jscode on the page:

console.log(document.referrer)

Versions

3.3.1 cypress (chromium 73 and electron 61)
Kubuntu 18.04

@jennifer-shehane
Copy link
Member

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 ''; } })
}

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label May 24, 2019
@jennifer-shehane jennifer-shehane added pkg/driver This is due to an issue in the packages/driver directory good first issue Good for newcomers labels May 24, 2019
@malshalabi
Copy link

Hey @jennifer-shehane, will you guys fix this soon?! I am facing the exact same case right now

@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Oct 15, 2021
@klarzynskik
Copy link
Contributor

Hey @jennifer-shehane, I'd like to work on that one. Is that okay?

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: waiting and removed stage: backlog stage: needs review The PR code is done & tested, needs review labels Oct 27, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 10, 2021

Released in 9.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.0.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Nov 10, 2021
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants