// HACKER NEWS — CYBERSECURITY
YouTube had a bug – I used ChatGPT to investigate
In the past few days, I noticed a bug I could not keep ignoring. Sometimes YouTube would randomly skip back in time during soft reloads, and whenever I would reload a video I did not finish watching, it would load noticeably earlier than the point where I stopped watching. This pissed me off so much I chose to dig into this issue as deeply as I could, with the goal of opening a ticket to Google and telling them "You have this issue, this is where the problem is, here is the fix, fix it and stop pushing slop." The resulting investigation produced something a bit less dramatic, but still quite insightful. So I decided to share.
I started off a bit too ambitious - I noticed a similar bug on Instagram which also appeared recently, and queried ChatGPT to figure out if Instagram and YouTube had anything in common in their stack. It was a long shot, and did not make much sense, but with the power of a thousand PhDs at my disposal, I figured I might as well churn some tokens and see where it leads. It thought for a while, and produced some interesting speculations... I chose to ignore all that, and narrowed my scope to the YouTube bug only.
I started messing about, changing tabs, pausing, unpausing, doing all kinds of things trying to reproduce the skip back in time behavior. It did not work. I concluded this mainly happens on soft reloads, i.e., when I watch YouTube, pause, and come back to that tab much later. I chose to assume that the main issue is not hidden in the soft reload itself, but rather in the restoration of checkpoint timestamps. So I paused a video, closed the tab, opened it - and voilà! - it restored the video quite a bit before where I paused it, 20 seconds earlier, to be precise.
I started tinkering further - I closed the tab again and reopened it - another 20-second drift.Then I closed the whole browser and reopened it - an additional 20-second rewind.In fact - I discovered a new YouTube hotkey; you can close the tab with Ctrl+W and reopen with Ctrl+Shift+T - this will rewind 20 seconds; do it enough times and you can easily rewind to any point in the video in case you missed something.They should really document all their hotkeys:
I also found that, for the same checkpoint, if I load it in the web browser I get the bug, but if I use the Android app for YouTube, it loads the right time, every time.Even if I close the tab on the browser, I will get exactly the point where I left off once I open up the YouTube history on my phone, but if I reopen in my browser - I am forced to live through a strong sense of deja vu.
(After some sleep I understood what was causing the difference between the web app and the Android app behavior, but you will have to read to the end to find that out.)
In the world of web development, we have the privilege of having the code the developers wrote run directly in the browser, and the browser - the beast that it is - gives us a set of development tools. These tools allow us to debug any shitty code we come across when browsing the web; usually, the smelly code I choose to debug is written by me, but today, the code belonged to somebody working for a small indie company named Google.
If you are running Chrome, press F12 with a web page open. You can deep dive into what makes that page tick. You can inspect the source of HTML and the different elements, where they are located on the page, what CSS styling is applied to them, etc. You can add and remove those elements. Most importantly for our topic - you can see the JavaScript code which is being run; you can debug it, set breakpoints, and see the call stack. You can also modify everything on the page straight in those developer tools, including hacking the JavaScript.
This is very useful, because YouTube runs in the browser, and if there are bugs, you can see the code which produces them - as long as it is run on the client. (Unfortunately, some code runs on the server which we cannot access.) The main caveat is that the JS code is o