TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How to automate collecting HAR file while user is browsing

25 pointsby royalghost4 months ago
Hello<p>We are facing an intermittent issue in our web application where for some users for some reasons http requests are ending in error ( 400s ) esp. during token refresh with authentication server.<p>Normally, we would ask user to generate the HAR ( HTTP archive file ) and we inspect to find the root cause. However, at this time it is challenging to collect the HAR file manually because the error is not consistent. Sometimes it seems to goes away but suddenly appears causing bad user experience.<p>It is also hard to add logs etc. because the token refresh happens on the client side from the browser so technically there is no traces of it on the server side.<p>I am looking into ways to automate generating the HAR file but it seems not straightforward to do it.<p>If anyone of you have faces similar issue in the past and find a way to add such error logging in a web service let me know. Any other thoughts and suggestions are highly appreciated.<p>Thank you in advance.

14 comments

lolinder4 months ago
This isn&#x27;t a direct answer to your question, but be very careful with asking for HAR files. They&#x27;re super convenient, but if your tech support doesn&#x27;t understand that HAR files are the worst kind of PII you can get in big trouble.<p>I&#x27;ve seen HAR files containing Google account session tokens attached in plain text to Jira tickets. If you end up leaking those tokens your customers will <i>not</i> be amused.<p>See the Okta breach:<p><a href="https:&#x2F;&#x2F;www.rezonate.io&#x2F;blog&#x2F;har-files-attack-okta-customers&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.rezonate.io&#x2F;blog&#x2F;har-files-attack-okta-customers...</a>
smittywerben4 months ago
What was the body of the HTTP 400? You should log that. Maybe there&#x27;s a refresh token grace period depending on implementation.<p>I&#x27;d sooner be testing in a lab environment recording a pcap file on both sides to try to get the client&#x27;s TLS session to break before I&#x27;d want a client&#x27;s confidential credential flow sent to me. I don&#x27;t like to bother people. I&#x27;ve always hated refresh tokens, at least OAuth&#x27;s design of them. Is sending a client&#x27;s decrypted MITM logs around really safer?
alp1n3_eth4 months ago
How intermittent of an issue is it? I don&#x27;t think collecting client side HAR files from real customers is the way to go, even if they&#x27;re willing. What happens when the next weird error shows up? More HAR files?<p>Echoing some other suggestions, but to a different extent, increase logging in the problem areas both client-side and server-side. It might be directly related to the token refresh since it only happens there, so a great place to start is within that functionality. Log the entire connection&#x27;s info to both services (front and back logging) and if users are manually submitting tickets you should be able to track them down by userID &#x2F; IP in the logs.<p>Also extend the fuzzing capabilities w&#x2F; your tests through browser (potentially could be headless, depending on the issue) automation that authenticates and uses the app &quot;normally&quot;. Keep it on repeat using the app and when token refresh time comes see if the error pops up. Throw some extra variables in their, ensure its off the corporate network or routed through DCs farther away to see if it&#x27;s a latency issue somewhere else. You could log the HAR file for this.<p>Multiple versions of tests might need to be run in parallel with different modifiers, such as one being allowed to directly communicate w&#x2F; the origin, vs. another going through the CDN like a standard customer would.<p>This is also an edge-case, but I&#x27;ve seen it popup sometimes; ensure that there aren&#x27;t any other required variables that are missing during the refresh process. Sometimes specific functionality in some apps is tied to a custom header, and sometimes the value isn&#x27;t updated to what the app expects. Things like that which could throw the process of from another angle.
solardev4 months ago
HAR files are big and it seems like overkill to send them every time. Can&#x27;t you make just make a client side fetch to an error reporting service? i.e. if the app detects a 400, then it sends a (no auth required) payload of the failed request &amp; response, with secrets sanitized, to another error reporting endpoint.
评论 #42827735 未加载
davidt844 months ago
As that&#x27;s pretty much spying on the user, I don&#x27;t think browsers make it easy to do that.
评论 #42830340 未加载
geocar4 months ago
Is this a CSP thing? Can you get away with <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTTP&#x2F;Headers&#x2F;Reporting-Endpoints" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTTP&#x2F;Headers&#x2F;Re...</a> and window.onerror?<p>Also, do you actually need the HAR file? or just a log of your servers&#x27; inputs&#x2F;outputs from the clients&#x27; perspective? You can get that The Boring Way if you don&#x27;t have a CSP issue, so maybe solve that issue?
dewey4 months ago
Might be overkill for something like this but tools like Sentry could also help you track it down more easily without any action by the customer.
phrotoma4 months ago
I think fullstory.com does this or something very like it. Not affiliated, just friends with some folks who work there.
viraptor4 months ago
&gt; the token refresh happens on the client side from the browser<p>You can totally add logging for that. If you don&#x27;t have an existing service that can handle it, you can create a logging-only endpoint for that purpose and send the event async to not block other work.
Zanfa4 months ago
I don’t remember how we debugged it at the time, but I’ve run into very similar symptoms that were caused by clock skew between client &amp; servers. Increasing the validity window to both past &amp; future by a longer period helped resolve it.
sim7c004 months ago
commendable that you wanna go this way honestly. i see a lot of companies just push bullshit back onto users in the face of this type of intermittent client side issue. repeating same dumb questions until you give up.<p>as some other commenter said, automating har files might not be ideal as it could collect much too much info, and browsers will make this very difficult to automate.<p>perhaps you cam add client side logging and automate gathering that or ask users for that rather than a har file. like if xyz happens again please send us log from location yzw. not sure if that is possible but it would atleast unburden users from runing devtools on an intermittent issue. if it happens only to few users you can add it optionally to their clientside like a debug&#x2F;trace mode. if it happens widespread id say add it for all users.<p>good luck and happy to see ur not giving up just yet :D these issues can be quite frustrating to get good data on. keep at it and ull find it eventually.<p>it might also be possible to automate a client at your own side and run it until it hits the issue. no guarantee it will actually hit it though. you can run it from office, home, and try to have many colleagues &#x2F; people run it in different (maybe personal) setups.
评论 #42829187 未加载
new_user_final4 months ago
I haven&#x27;t used it, but you can try if it works for you. It has custom dev tools.<p><a href="https:&#x2F;&#x2F;eruda.liriliri.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eruda.liriliri.io&#x2F;</a>
mariogintili4 months ago
can&#x27;t you just do window.onerror = aFunctionThatReports400ErrorsWithAllTheDataYouNeed();
moltar4 months ago
Have you tried Sentry with replay?