I'm trying to enable logging in Chrome using the command-line flags `--enable-logging --v=1`, but I find that nothing is being saved in the logs stored in `%LOCALAPPDATA%GoogleChromeUser Data`. Every time I perform a Google search, it suggests that output should be generated, yet I just end up with an empty file. I'm curious if there's a setting I might be missing or if something has changed recently.
My goal is to capture app errors happening on the client side of a web application I'm running with technologies like PHP, VueJS, TypeScript, and jQuery. Users sometimes report issues where things don't work or aren't visible, and currently, we need them to open Developer Tools and share what they see in the Console.
I'd love to log these errors instead. What's the best way to accomplish that and ensure they're captured in a file?
3 Answers
The logging options in Chrome primarily track internal browser events, not your app's errors. You can catch errors manually in your script with something like `window.addEventListener('error', e => sendLog({message: e.message, stack: e.error?.stack}));` to send them over to your server for logging. Keep in mind that you'll need your server to handle these requests and save the info somewhere for review.
It seems like the flags you're using are intended for Chrome's internal logging rather than capturing JavaScript console errors from your app. To properly log client-side errors, you should implement error handling directly in your code. Try using `window.onerror` to catch errors and send them to your server via POST requests. It's a reliable method to keep track of what's going wrong without relying on Chrome's logging capabilities. If you're not already doing this, consider setting up a simple endpoint to log errors on your server, like logging them to a database or a file.
You're correct that Chrome's logging flags won't capture console errors from your web app. For effective error logging, you should add error handling in your app code. Implement `window.addEventListener('error', e => { /* your logging logic */ })` to catch JavaScript errors and post them to your server. This approach is superior to hoping that Chrome logs your app's issues. You could also integrate tools like Sentry for error tracking, which can provide extra insights without heavy lifting.

Related Questions
Keep Your Screen Awake Tool
Favicon Generator
JWT Token Decoder and Viewer
Ethernet Signal Loss Calculator
Glassmorphism CSS Generator with Live Preview
Remove Duplicate Items From List