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

visit() does not send user agent header as specified #3719

Songyu-Wang opened this issue Mar 15, 2019 · 5 comments

visit() does not send user agent header as specified #3719

Songyu-Wang opened this issue Mar 15, 2019 · 5 comments


Copy link

@Songyu-Wang Songyu-Wang commented Mar 15, 2019

Current behavior:

With the new feature in 3.2.0 that enables setting headers for visit(), "user agent" header is not correctly passed to server side

Desired behavior:

user agent header can be passed to server side as specified

Steps to reproduce: (app code and test code)

Using the following code:

      url: '/',
      headers: {
        'User-Agent': 'bad browser',
        'hello': 'hi'

And observe server side receives something like this:

As shown above, header "hello" is correctly passed, therefore the header setting is recognized by cypress. However, header "User-Agent" is still my real browser which is the error


cypress 3.2.0

Copy link

@flotwig flotwig commented Mar 15, 2019

It's probably because the UA header gets clobbered in two places in

From a first glance, it looks like this is just Cypress trying to pass along the UA of the browser with the request. It'd probably be safe to change these lines to have and !headers["user-agent"] or similar to allow UA to be overridden.

Need to make sure we're normalizing headers to be lowercase before that can happen.

Copy link

@jennifer-shehane jennifer-shehane commented Mar 18, 2019

You can set the userAgent as a configuration value in your cypress.json file -

There's some explanation on why we implemented it this way here: #364

headers lowercase issue: #2879

We should document this more clearly though within the cy.visit() doc though.
I created a new issue in our docs to document this here: cypress-io/cypress-documentation#1498. Our documentation is open source and contributions are welcome. 😄

Copy link

@jennifer-shehane jennifer-shehane commented Mar 19, 2019

After further discussion - we should probably also at least handle warning the user when passing a User-Agent header that there is another way to implement this (if not change the implementation to work altogether), so we reopened.

Copy link

@cypress-bot cypress-bot bot commented May 1, 2019

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

Copy link

@cypress-bot cypress-bot bot commented May 17, 2019

Released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants