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.

Incorrect document.domain

See original GitHub issue

Current behavior:

When running Cypress against a subdomain (e.g. sub.example.com), document.domain is reported as example.com.

Desired behavior:

document.domain should be the full domain name sub.example.com.

Steps to reproduce:

Run a Cypress test against a subdomain:

cy.visit("https://en.m.wikipedia.org/wiki/Main_Page")

Then run document.domain in the dev console. Expected output: "en.m.wikipedia.org".

Versions

Latest Cypress using Chrome Canary.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
jennifer-shehanecommented, Aug 26, 2019

We reviewed this as a team and have decided that while this is unexpected behavior, we won’t be changing this behavior in Cypress today.

With the way Cypress works today, we have to set the document.domain in this way to avoid issues with visiting other subdomains. If this is causing problems within your testing, we suggest updating your application code, so that when visiting during testing, within a testing environment, it removes any limitations around the document.domain issue.

To more directly address @tdelphi, in this case, from the information you provided, we would recommend turning off the OWASP CSRFGuard restrictions during testing.

A simple way to check if your application is running while being visited within Cypress can be found here. I’d suggest a combination of detecting Cypress and also knowing that the tests are being run from within your own development team - then changing the application logic in this instance.

@nicojs I’m not sure about the issue you are encountering exactly, since you never described it, so let us know if there is some limitations to our suggestion.

We’re always welcome to reconsider fixing this or offering a better workaround or errors in the future. So, please comment if you have objections to our suggestion.

6reactions
sscaff1commented, Mar 8, 2021

We have the same situation with a very old application. This is preventing us from using cypress for testing…We were hoping to move from Selenium to Cypress…

Why can’t this be configurable?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document.domain - Web APIs - MDN Web Docs
The domain property of the Document interface gets/sets the domain portion of the origin of the current document, as used by the same-origin ......
Read more >
Chrome solution for document.domain - Stack Overflow
domain = "foo.com" // Still ok document.domain = "bar.foo.com" // Invalid, you can't change it back to a more specific domain.
Read more >
What is document domain, and how do I change it?
Changing domains. To change your domain/document type in the Grammarly Editor, select Goals on the right. In the window that opens next, ...
Read more >
Problem with document.domain - CodeRanch
I am working with popup windows which are stored in two different domains(say server1 and server2). Hence I try to set the document.domain=" ......
Read more >
15313 – Same-origin check wrong when document.domain set
Internet Explorer 6: Protocol mismatch, document.domain set: Denied. ... its document.domain, the old code "worked" because it incorrectly ...
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