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.

Debugging tricks in the browser

646 pointsby bkudriaover 1 year ago

16 comments

lewisjoeover 1 year ago
The debugging tools built within the browsers have come a long way in the last couple of decades. I&#x27;m a JS veteran and I&#x27;m deeply grateful to all the people putting in such efforts to make debugging code in the browser so intuitive.<p>Whenever I go to a different zone of development, like backend or a different language, I miss this ecosystem of debugging tools that modern browsers have by default.
评论 #38231624 未加载
评论 #38233447 未加载
评论 #38231616 未加载
Jerrrryover 1 year ago
&gt;&gt;setTimeout(function() { debugger; }, 5000);<p>This is clever; after all, the only way to beat the recursive turtle stack of chrome debuggers debugging themselves is with the debugger statement.<p>sam.pl, of the infamous myspace Sammy worm, used debugging gotcha&#x27;s to prevent visitors from de-mystifying his obfuscated html homepage.
评论 #38229622 未加载
评论 #38228791 未加载
评论 #38233516 未加载
评论 #38245998 未加载
评论 #38228894 未加载
评论 #38228227 未加载
adamnemecekover 1 year ago
`queryObjects` is notably missing. It is a crazy API which returns a list of all objects created by a particular constructor. One can for example get a list of all functions on the heap by doing `queryObjects(Function)`.<p>This will return even functions contained in some module that are “private”.
评论 #38227839 未加载
评论 #38228801 未加载
评论 #38228936 未加载
russellbeattieover 1 year ago
I can never get watched variables to work. The scoping and updating rules for it are a mystery to me. I assume only global variables can be watched, but even then it never works as I expect, so I end up just flooding the log with values when testing.<p>I&#x27;ve thought for years the console should add Data.gui [1] style UI for viewing&#x2F;testing variable and settings values. You can see it action on this CodePen [2].<p>1. <a href="https:&#x2F;&#x2F;github.com&#x2F;dataarts&#x2F;dat.gui">https:&#x2F;&#x2F;github.com&#x2F;dataarts&#x2F;dat.gui</a><p>2. <a href="https:&#x2F;&#x2F;codepen.io&#x2F;russellbeattie&#x2F;full&#x2F;kGxaqM" rel="nofollow noreferrer">https:&#x2F;&#x2F;codepen.io&#x2F;russellbeattie&#x2F;full&#x2F;kGxaqM</a>
评论 #38228201 未加载
评论 #38239044 未加载
评论 #38229058 未加载
amlutoover 1 year ago
I’d like to see a way to access local variables of an IIFE, without breaking into code in the IIFE’s scope. Is there some way to convince the debugger to do this?
评论 #38227635 未加载
评论 #38227562 未加载
评论 #38230405 未加载
评论 #38231552 未加载
评论 #38274757 未加载
评论 #38233957 未加载
评论 #38245103 未加载
adr1anover 1 year ago
For the sake of completeness, I can recommend Werkzeug. I use it for Django backend development and it&#x27;s incredibly useful. It allows me to have &quot;PDB&quot; shell right in the browser whenever and wherever an exception is met.
评论 #38230808 未加载
评论 #38273153 未加载
评论 #38232792 未加载
Invizover 1 year ago
One trick i use all the time is debugging by searching through loaded scripts by UI string:<p>1) Go to Network panel, start recording network requests<p>2) Open left sidebar and invoke search to type in the code&#x2F;ui string you want to find<p>3) It&#x27;ll usually find it in some weird bundled js chunk file, click on the result<p>4) It opens the network request for that file, now right click anywhere in file and pick &quot;Open in Sources&quot; or something along that line, that jumps to debugger<p>5) Now place your debugger statement, this will probably load sourcemaps too
Mizzaover 1 year ago
I&#x27;ve been a Python&#x2F;Elixir programmer for a long time and I make heavy use of pdb.set_trace()&#x2F;IEx.pry().<p>Lately, I&#x27;ve inherited a very messy NodeJS backend and have been pulling my remaining hair out working without proper debugging tools. I&#x27;ve gone back to &#x27;console.log&#x27; debugging, but it makes me feel like a caveman.<p>I can&#x27;t believe that this whole popular ecosystem doesn&#x27;t have a proper debugging REPL - can anybody point me in the right direction?
评论 #38229525 未加载
评论 #38229517 未加载
评论 #38231539 未加载
评论 #38232775 未加载
评论 #38232649 未加载
BMoreartyover 1 year ago
Under the section &quot;Debugging Property Reads&quot;: how would you convert `{configOption: true}` to `{get configOption() { debugger; return true; }}` using a conditional breakpoint?
评论 #38239039 未加载
rootsudoover 1 year ago
This is something I really need to pick up &#x2F; is there a dedicated book or study for this or is it just web dev &#x2F; front end all the way down?
评论 #38228544 未加载
quotemstrover 1 year ago
Don&#x27;t any browsers support re-style reverse debugging yet?
elpachongcoover 1 year ago
I haven&#x27;t had the need to use it but I&#x27;ve been thinking if something like the last one `Monitor Events for Element` exists. Glad it does. Although according to the article, it&#x27;s a Chrome-only feature. I wonder if there are any alternatives for Firefox?
Andrews54757over 1 year ago
I&#x27;ve noticed that a lot of websites will try to prevent you from using the debugger. They use various techniques ranging from calling `debugger` every second to entrapped sourcemaps to make debugger features work against you!<p>Take a look at disable-devtool [1], it surprises me just how many methods can be used to detect usage of an invaluable tool that should be a user&#x27;s right to use. These &quot;exploits&quot; should really be patched browser-side, but I don&#x27;t see any active efforts by browsers to fix this.<p>I&#x27;ve created a simple anti-anti-debug extension [2] that monkey-patches my way around these anti-debug scripts. It works fine for now, but I can&#x27;t imagine it working consistently in the long term once the inevitable arms race begins.<p>How can we get Google, Mozilla, etc... to care about dev tool accessibility?<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;theajack&#x2F;disable-devtool">https:&#x2F;&#x2F;github.com&#x2F;theajack&#x2F;disable-devtool</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;Andrews54757&#x2F;Anti-Anti-Debug">https:&#x2F;&#x2F;github.com&#x2F;Andrews54757&#x2F;Anti-Anti-Debug</a>
评论 #38227610 未加载
评论 #38227475 未加载
评论 #38227606 未加载
评论 #38227680 未加载
评论 #38227408 未加载
temporallobeover 1 year ago
None of these are weird or something the browser is trying to hide from you, just things that an experienced front-end developer would probably know, although I was not aware of the monitor() command.<p>That being said, I am pleasantly surprised at the debugging and development tooling that is built right into most modern browsers. It really does make the UI development experience very powerful. I wish more back-end languages had this experience.
评论 #38227476 未加载
评论 #38227383 未加载
评论 #38227375 未加载
评论 #38228111 未加载
评论 #38228628 未加载
acemarkeover 1 year ago
I&#x27;m going to put in a very relevant self-plug for the tool that I work on.<p>I work at Replay.io, and we&#x27;re building a true &quot;time traveling debugger&quot; for JS. Our app is meant to help simplify debugging scenarios by making it easy to record, reproduce and investigate your code.<p>The basic idea of Replay: Use our fork of Firefox or Chrome to make a recording of your app, load the recording in our debugger UI, and you can pause at _any_ point in the recording. In fact, you can add print statements to any line of code, and it will show you what it _would_ have printed _every time that line of code ran_!<p>From there, you can jump to any of those print statement hits, and do typical step debugging and inspection of variables. So, it&#x27;s the best of both worlds - you can use print statements <i>and</i> step debugging, together, at any point in time in the recording. It also lets you inspect the DOM and the React component tree at any point as well.<p>I honestly wish I&#x27;d had Replay available much earlier in my career. I can think of quite a few bugs that I spent hours on that would have been _much_ easier to solve with a Replay recording. And as an OSS maintainer for Redux, there&#x27;s been a number of bugs that I was _only_ able to solve myself in the last year because I was able to make a recording of a repro and investigate it further (like a tough subscription timing issue in RTK Query, or a transpilation issue in the RTK listener middleware).<p>If anyone would like to try it out, see <a href="https:&#x2F;&#x2F;replay.io&#x2F;record-bugs" rel="nofollow noreferrer">https:&#x2F;&#x2F;replay.io&#x2F;record-bugs</a> for the getting started steps to use Replay (although FYI we&#x27;re in the middle of a transition from Firefox to Chromium as our primary recording browser fork).<p>I also did a &quot;Learn with Jason&quot; episode where we talked about debugging concepts in general, looked at browser devtools UI features specifically, and then did an example of recording and debugging with Replay: <a href="https:&#x2F;&#x2F;www.learnwithjason.dev&#x2F;travel-through-time-to-debug-javascript" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.learnwithjason.dev&#x2F;travel-through-time-to-debug-...</a><p>If you&#x27;ve got any questions, please come by our Discord and ask! <a href="https:&#x2F;&#x2F;replay.io&#x2F;discord" rel="nofollow noreferrer">https:&#x2F;&#x2F;replay.io&#x2F;discord</a>
评论 #38227975 未加载
评论 #38228503 未加载
评论 #38228574 未加载
评论 #38228161 未加载
评论 #38227963 未加载
评论 #38233885 未加载
评论 #38228626 未加载
thrdbndndnover 1 year ago
Probably a good place to ask a specific question about debugging here.<p>A few years ago, I was hacking a web bookreader.<p>It has a function that is used to decode images (they&#x27;re encrypted in some way) into canvas, and I want to find it so I can call it directly in my user script to batch download decoded images.<p>So I monkey patched `CanvasRenderingContext2D` function, added breakpoint, and found where the the function is defined in the 100k lines of obfuscated JS source code, easily.<p>The problem is.. once the page is rendered, the function would be nested in some objects, something like `window.abd.fdsfsd.r2323.fsdfs.fasf.xyy.myfunc`.<p>I don&#x27;t know how exactly I can find the full &quot;path&quot; of the function so I can call it, despite I&#x27;m literally pausing inside of it. I eventually got it done, but it was manual and painful.<p>So I&#x27;m wandering: is there a better way to do it? The browser obviously knows it, it just lacks of a way to tell.
评论 #38230425 未加载
评论 #38229212 未加载
评论 #38231697 未加载
评论 #38230153 未加载
评论 #38229760 未加载
评论 #38229946 未加载