Hide HTTP Requests in Cypress Command Log
This guide shows you how to hide HTTP requests from the Cypress Command Log, making your test output cleaner and easier to read. You’ll learn to suppress the display of network calls (like cy.request, cy.intercept, and XHR/fetch logs) while keeping the underlying behavior intact. No special plugins are required—just a few Cypress configuration options and a custom command.
What You’ll Need
- A Cypress project (version 10 or later recommended; the steps work for earlier versions with minor adjustments).
- Basic familiarity with Cypress commands and configuration files (
cypress.config.jsorcypress.json). - Access to your test files and support file (usually
cypress/support/e2e.js).
Step-by-Step
- Open your Cypress configuration file. Locate
cypress.config.js(orcypress.jsonin older versions) in the project root. - Disable request logging globally. In the configuration object, add the key
requestLoggingand set it tofalse. This hides the default log entries forcy.requestandcy.interceptcalls. Example forcypress.config.js:module.exports = defineConfig({ e2e: { requestLogging: false, // other options } });For older
cypress.json, add"requestLogging": falseat the top level. - Suppress XHR and fetch logs. Cypress logs these automatically when they occur. To hide them, add a
beforehook in your support file (cypress/support/e2e.jsorcypress/support/index.js) that overrides thecy.originor uses a custom command. The simplest way is to use theCypress.onevent to filter out log entries of typerequestandresponse:before(() => { Cypress.on('log:changed', (log) => { if (log.attributes.type === 'request' || log.attributes.type === 'response') { log.attributes.hidden = true; } }); });This hides the log entries from the Command Log without affecting the actual network activity.
- Hide specific intercept logs. If you want to keep some request logs but hide others, you can use
cy.interceptwith alog: falseoption (available in Cypress 10+). For example:cy.intercept('GET', '/api/users', { log: false }).as('getUsers');This hides the log for that specific intercept while others remain visible.
- Create a custom command to hide all requests on demand. In your support file, define a command like
cy.hideNetworkLogs()that sets a flag and applies the filter:Cypress.Commands.add('hideNetworkLogs', () => { Cypress.on('log:changed', (log) => { if (log.attributes.type === 'request' || log.attributes.type === 'response') { log.attributes.hidden = true; } }); });Then call
cy.hideNetworkLogs()at the start of any test where you want to clean up the log. - Verify the changes. Run your tests. Open the Command Log in the Cypress runner. You should see that network requests no longer appear as individual log entries, though they still happen and can be awaited via aliases.
Common Mistakes
- Setting
requestLogging: falsein the wrong place. Incypress.config.js, it must be inside thee2eobject, not at the top level (unless usingcypress.json). - Using
log: falseoncy.requestincorrectly. Thelogoption forcy.requestislog: false(as a Cypress option), but it only hides the command log, not the network tab. For full hiding, use the event filter. - Forgetting to put the
beforehook in the support file. If you put it in a test file, it only applies to that spec, not globally. - Overriding
log:changedmultiple times. If you add multiple listeners, they may conflict. Use a single listener or a custom command to manage it.
Tips
- Use aliases to keep track of requests. Even if you hide logs, you can still use
cy.wait('@alias')to ensure the request happened and inspect its response. - Hide only after a certain point. You can call
cy.hideNetworkLogs()mid-test to keep early logs visible for debugging, then clean up later. - Combine with
cy.interceptto stub responses. Hiding logs does not affect stubbing; you can still mock responses and hide the logs for a clean test output. - Use the
log: falseoption forcy.interceptselectively. This is useful when you only want to hide a few specific API calls, not all.
Troubleshooting
- Requests still appear in the log. Check that you have placed the
Cypress.on('log:changed')listener correctly. It must be inside abeforehook or at the top of the support file. Also ensure you are using the correct log type names (requestandresponseare lowercase). - The
requestLoggingoption does nothing. This option was introduced in Cypress 10. If you are on an older version, it may not exist. Instead, rely on the event filter method. - Hiding logs breaks
cy.wait. Hiding logs does not affect the actual network behavior. Ifcy.waitfails, it is likely due to a timeout or a mismatch in the alias—not because the log is hidden. - Custom command not found. Make sure you define the custom command in the support file and that the support file is loaded (check
supportFilein your config).
Frequently Asked Questions
Does hiding HTTP requests affect the test execution?
No. Hiding logs only changes what is displayed in the Command Log. The requests still occur, and you can still use cy.wait and assertions on responses.
Can I hide only certain types of requests (e.g., only XHR, not fetch)?
Yes. In the log:changed handler, you can check the log.attributes.name or other properties to filter more specifically. For example, you can hide only logs where log.attributes.url contains a certain pattern.
Will this work with Cypress 9 and earlier?
Yes, the Cypress.on('log:changed') approach works in Cypress 6 and later. The requestLogging config option is only available in Cypress 10+, so use the event filter for older versions.
Can I hide logs for a single test without affecting others?
Yes. Call cy.hideNetworkLogs() inside that test, or use a beforeEach hook in that specific spec file. The listener will be active for that test only.
Does hiding logs improve test performance?
Not significantly. The main benefit is readability. The overhead of logging is minimal, but hiding can reduce the amount of data Cypress stores in memory for the log, which might help with very large test suites.
Can I hide logs in the Cypress Dashboard (recorded runs)?
Yes, the same configuration applies to recorded runs. The Command Log in the Dashboard will also omit the hidden entries.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.