Basics for Debugging with Browser Consoles
On this page
- Toggle pseudo-classes to trigger styling rules
- Use responsive design mode to develop responsive interface
- Use computed styling to detect active styling rules
- Use Console Panel to print out information for debugging
- Filter requests in Network Panel for better information
- Manipulate Cache
- Read and Manipulate Cookies and Session Storage data
- References
Toggle pseudo-classes to trigger styling rules
Some user’s interaction with HTML element would trigger extra styling rules (.e.g. hover on top of button makes the color changes, focus on an input makes it being highlighted). Modern browsers allow developer to trigger these behaviors via browser console.
Guidances:
- Chrome: https://developer.chrome.com/blog/triggering-of-pseudo-classes/ (the same usage method applied to most browsers)
Use responsive design mode to develop responsive interface
To test how the interface looks like in different devices, the browser console allows to manipulate display screen size or even simulate different devices on the browser
Guidances:
- Chrome: https://developer.chrome.com/docs/devtools/device-mode/ . The same usage applied for other Chromium browsers like Microsoft Edge
- Firefox: https://firefox-source-docs.mozilla.org/devtools-user/responsive_design_mode/
Use computed styling to detect active styling rules
More often than not, a component styling is a combination of different styling rules. The browser console supports highlights of current active styling rule, and where the rules come from via computed styling panel. Developer can use this to navigate and discover unwanted styling rules.
Guidances:
Use Console Panel to print out information for debugging
console.log
is a quick, ‘dirty` way to print out information for debugging. Developer can utilize this to get information in runtime in Console Panel of Browser Console
DO: using console.log
, console.info
, console.warning
and console.error
to create layers of information. The browser console supports filters based on type of console messages
DON’T: all debugging information has to be removed in production build. Most modern frameworks have configuration parameters to handle this, for example with Vite
Filter requests in Network Panel for better information
Network Panel is an important part of browser console - it shows to developer all requests and data received during runtime. However, sometimes developer only needs to see specific types of requests, e.g. XHR requests or JS files. Filtering them by categories is recommended in such situations
Guidances:
Manipulate Cache
In development and debug, it is recommended to disable all caches to detect bottleneck when the website loads. The cache can be old HTML or JS files, or responses from APIs previously called.
Guidances:
- Chrome: https://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development
- Firefox: https://stackoverflow.com/questions/20884511/how-can-i-turn-off-cache-in-firefox-only-when-developer-tools-are-opened
Read and Manipulate Cookies and Session Storage data
There are some use cases where you want to be able to manupulate cookies or session storage data
- When you need to clear off current user’s session data to quickly logout
- Observe size and information cached in session storage
- Copy cookies info to use in other tool like Postman