Fixing a bug in Google Chrome as a first-time contributor

by Ameoon 8/26/2024, 9:10 AMwith 165 comments

by mherrmannon 8/26/2024, 11:13 AM

Congratulations! And thank you for the great write-up. I work with the Chromium code base a lot, and it can indeed be daunting. I use Sublime Text, which treats the code as plain text, apart from syntax highlighting. But it's also possible with at least VS Code to get some more intelligence, such as going to the definition or declaration of a function, etc.

People who have now become interested in creating their own Chromium-based browser may want to take a look at my article: https://omaha-consulting.com/how-to-fork-chromium. It gives a high-level view of what goes into maintaining a Chromium fork.

by macqmon 8/26/2024, 4:54 PM

>Because of this huge codebase size, I wasn't able to get VS Code's C++ extension to work very well with the project. Features like go-to definition (which I usually rely on heavily when navigating codebases) and find references didn't work well or at all, and one of my CPU cores would stay stuck at 100% permanently while the project was open.

Chromium Code Search [1] tool is very helpful with that and I believe there are some extensions that integrate with it.

1: https://source.chromium.org/chromium/chromium/src

by kgeiston 8/26/2024, 1:20 PM

Chromium's codebase isn't so bad for a first timer. Years ago our product had a bug on Windows where if you paste an image from the clipboard, the image had garbage in it (something to do with alpha channels). I realized Chrome has no such bug so they probably had a workaround. It took me like 30 minutes of lurking around in the codebase for the first time to find their workaround and apply it to our code.

by mrweaselon 8/26/2024, 11:33 AM

Not that I really see away around it, given the size and feature set of Chrome, but those build requirements are just crazy. It kinda throws the open source and "everyone can contribute" model out the window, if you can't afford a pretty insane workstation then you're going to have a bad time.

I doubt that Firefox is better, I seem to remember that building Firefox and the VIA C3 processor years back as around half a day of compiling, but was also an extremely poorly choose CPU for the task.

by quirinoon 8/26/2024, 2:38 PM

There's this one Chrome (?) bug I've been experiencing for a long time on Linux.

Every once in a while, the browser detects I'm typing "±±±±±±+..." and writes that to any selected text input. It stops when I type anything, but sometimes comes back rather quickly.

I thought it was a keyboard issue, but it doesn't affect Firefox or other applications, only Chrome based ones like Spotify and VSCode.

I've found no other mention of this on the internet and I'd love to to hunt this down and fix it but have no clue where to start. I guess the first step would be to consistently reproduce the bug...

If you're interested, I screen recorded it happening once. Mind there's music playing: https://youtu.be/S7OGTULLsqg.

by evmaron 8/26/2024, 5:03 PM

This post is really great! My biggest piece of advice to someone attempting to do the same is to browse the code via the online code browser, which has working cross referencing. (The codebase is so large it is not the sort of index you can reliably build locally...)

https://cs.chromium.org is the easy URL to remember ("cs" for "code search")

by nunezon 8/26/2024, 1:21 PM

> I'll unashamedly admit that I made liberal use of printf debugging while trying to make my way through these code paths

Nothing to be ashamed of, imo; printf debugging works incredibly well!

by modelesson 8/26/2024, 3:32 PM

This is great! You should consider fixing the Chromium bugs you run into! Chrome releases relatively quickly, so in 4-6 weeks you can have a bug fixed forever for all of your users on Chrome.

I used to work on Chrome and WebKit and I still have committer status. I've often wondered if there are people out there who would be willing to pay a contributor to get their bug fixed, but don't know who to contact. Feel free to email me :)

by KolmogorovCompon 8/26/2024, 10:13 AM

> Although the worklet was running on a worker thread, it didn't have a WorkerGlobalScope - it had a WorkletGlobalScope.

It took me a while to see these were different, I thought it was a wrong copy-paste.

Naming things is hard, but this is a bad convention. Always put the changing bits at the beginning preferably, or the end otherwise, but never in the middle, especially when it's subtle in a rather verbose name.

by andaion 8/26/2024, 7:38 PM

I noticed in Chrome based browsers that when I copied an image to clipboard, whole UI would freeze. For large images it would become unresponsive for 5-10 seconds.

I dug into the source and turns out they PNG encode it, I believe at highest compression. (The comments indicate this is something to do with how old versions of MS WORD handle transparency..?)

My "workaround" was to change the compression level to 0. Not ideal but I only needed to change 1 byte in the exe, and I was glad I didn't need to rebuild all of Chrome!

Firefox has 0 lag and has the benefit that you can paste directly into file explorer, because they put the original image file into clipboard instead of image data.

by deckar01on 8/26/2024, 2:24 PM

> one thing that I was completely unsure about was how to add tests for this fix.

Similar to blaming the file for maintainers, the diff of those commits can direct you to their tests. The full patches that those commits belong to can also be useful for finding undocumented habits that have lead to approval.

https://stackoverflow.com/a/30998048

by sebstefanon 8/26/2024, 4:45 PM

>I started my debugging by finding where the network request for the worklet script was initiated and tracing it down as far as necessary until the request was actually made - or retrieved from the cache. The call tree looked something like this:

It completely escapes me how you can find that in such a codebase.

by genewitchon 8/26/2024, 5:36 PM

regarding the comments about the "build time" of firefox/chromium - a couple of weeks ago i installed gentoo 686 on an old netbook, including a DE/WM and firefox. I also told it to completely recompile everything that comes "preinstalled" in the stage3 gzip (that's prior to installing the WM and ff).

llvm took forever to compile, and then for some reason i needed to have two versions of llvm - i don't recall why offhand. So i have a devuan VM on my desktop here, i set up a gentoo chroot, updated it and installed distcc, installed distcc on the netbook - just like i've always done in these circumstances. Believe me when i say: it's still like magic, even if "distcc-pump" no longer works.

total time to get the netbook to a stable, running as i want it, useful machine - ~1 week. Results? It's actually useable - more usable than it was with windows 7 on it when it was new, and much more usable than whatever ubuntu i had installed on there 7 years ago or whatever.

I did, however, make a mistake. I didn't need to use i686 (32 bit) - the atom is a dualcore and on ark it shows that CPU is 64 bit. So i'll probably do all this again (after a reboot onto gentoo boot media and 'dd'ing /dev/sda2 to a network location, just in case). I may even see if it's possible to resurrect pump, because that will speed things up even more. If pump is working, the only thing that sucks about "emerge" on gentoo on a slow machine is waiting for the spinner at the beginning and the "installing <pkg> ..." parts of the flow, due to memory and CPU contstraints. I'm using an SSD in there so at least i got that going.

by ramshankeron 8/26/2024, 6:12 PM

Excellent. One small question If anyone can answer. When an outside contributor is submitting a fix like these, do open source software maintainers ask for test also to be written? Fix itself is worth acceptance. What if contributor don't have any more time/interest beyond submitting the fix.

by pilifon 8/26/2024, 12:28 PM

I'm coming out of reading this a bit dismayed as I really thought that the `if let` (to use the swift conventions) pattern would finally be a good and reliable solution for these silent errors.

And at the same time, reading the code in question and putting myself into the position of a person writing the code, I would totally have thought that I'm handling the "is there a global scope" case, totally forgetting that the same check is also checking the "is the global scope a `WorkerGlobalScope`" condition but mixing both checks into a single return value.

And here we are with the code happily chugging along and (for all intents and purposes) causing data corruption (by causing network requests to not be logged and not respect policy).

And here I was thinking that `if let` is fixing exactly this problem while also providing the best ergonomics.

So here we are back to the drawing board, ready for the next pattern which will compromise on ergonomics in some as-yet unknown way in the future.

by kenrick95on 8/26/2024, 11:30 AM

> but a clean build still takes something like 45 minutes to finish

I had a similar experience when building Firefox from source >.<

though I recall I had more trouble when pulling the codes as I was naive and pulled all the history

by pipeline_peakon 8/26/2024, 9:21 PM

I wonder how many more (quantity or quality) commits OP would have to make before getting interviewed as a chrome dev either by Google or another company that uses Chrome heavily like Samsung.

by thomasfromcdnjson 8/26/2024, 5:29 PM

That was a really good read, thank you!

by f1codzon 8/27/2024, 11:12 AM

> 33 million lines of code in total

Is that a fact? That seems insanely large.

by xyston 8/26/2024, 3:41 PM

A fun project would be to implement a cross platform compatible web browser in rust. Chromium just has so much baggage with it on top of years of Google junk.

by aronhegeduson 8/27/2024, 8:16 AM

Good write up! Well done!

by creeschon 8/26/2024, 11:40 AM

Interesting to read all of this. Bugs in more obscure areas being open for years is something I am pretty familiar with, although then on the Firefox side of things.

I personally never have been able to muster up the courage or energy to try and dive into the code base there, though. Part of that is simply because such a huge code base is daunting to delve into. But an even bigger stumbling block was always the prospect of having to deal with the entire process of submitting the fix and getting it approved. Certainly with Mozilla the interactions I have had on Bugzilla with various people there as well as in other places simply made me decide to work around the issues.

I am honestly surprised how relatively smooth the process seems to have been for the author, dealing with Chromium developers.

by Glaciaon 8/26/2024, 11:39 AM

On a similar note, i always wanted to contribute to Firefox, but every time i looked at how to compile it i noped the fuck out of it. It's probably is doable on linux but it's sounds like a nightmare on windows.

by varispeedon 8/26/2024, 11:51 AM

Have you got paid for this?

The reason I am asking is that I see volunteering time for extremely wealthy big corporations as foolish.

At very least developers should get together and lobby that if big corporations use open source software, they should be paying royalties to contributors.

That said, if you look at volunteering time, it is much better to do it for charities that often struggle getting competent IT people, but of course it is not as glamourous.