Show HN: Hackernews-Button – Bloom Filter-based, private HN browsing extension
github.com
github.com
Rather than determining if the current site has been submitted by querying the Firebase/Algolia APIs with every page you visit, the extension contains regularly-updating Bloom filters for all submitted HN stories to preserve user privacy. There is a single C library underlying both the code to generate Bloom filters, and the actual extension code (it is compiled to WebAssembly so the C functions can be called from JavaScript). I have included an architecture overview in the README to help a prospective reader get through the important parts of the code, and have tried to justify design decisions via extensive comments within the source.
I am happy to answer any questions! I'm also always looking for constructive criticism.
Nice!
I built a pi-hole esque stub dns-resolver that uses Bloom Filters generated from hostfiles (60 MiB, 5M entries --> 2 MiB with 1% false positives) and it worked like a charm. At some point, I also looked into Xor Filters which are apparently even lighter and faster but couldn't find a JavaScript implementation for it [0].
I; however, stopped using Bloom Filters because its immutability meant building it over and over again which was a pain. Inverted Bloom Filters [1] or Spectral Bloom Filters [2] might have been useful since they can be updated in-place. Instead, I went for storing hostnames in a Finite State Automata [3], which while not as compact as Bloom Filters, could be updated in-place, are deterministic, and search faster. Likely not a fit for your use-case however.
PinSketches, otoh, might be a fit for accomplishing efficient set reconciliation [4] of the filters you're distributing.
[0] https://github.com/FastFilter/xorfilter#implementations-of-x...
[1] https://www.youtube.com/watch?v=eIs9nJ-JFvA
[2] https://pncnmnp.github.io/blogs/spectral-bloom-filters.html
I had not heard of PinSketches before this, and will definitely look into them. As I mentioned in another comment: the way the project is set up, it should be possible to do a drop-in replacement with a better data structure, should one come along. Thanks!
I also really like using <details> tags so that interested users can dive into the documentation without everyone having to be hit with a massive README.
Your idea to add a "submit page" option would fit very nicely with this.
There are millions of posts on HN, how many submissions does it retrieve? Surely if you find an obscure site, it might not be in the local list.
Maybe you could just always query many urls together, with only 1 of them being the real url you want. That would make it hard to track too.
Also I made a similar extension, but it queries sources on every page load.
(extension) https://newsit.benwinding.com/
(source) https://github.com/benwinding/newsit
The code uses GitHub Actions to generate Bloom filters once every 24 hours, corresponding to the update frequency of the Hacker News BigQuery database that it pulls from. The 16MB Bloom filter for all stories ever has about 4M entries at the moment. As far as I know, this is every single story that has been previously submitted to HN.
Since Bloom filters are just long bit strings, you can OR them together to add stuff. This means you can download a smaller Bloom filter to update your current one, rather than downloading 16MB files all the time. The extension also auto-adds any stories linked on news.ycombinator.com pages you visit, so that stories too new to be in the Bloom filter are still added.
I like the [1] Workflow file you've made, the comments really help with reading shell code. I'm also amazed you can query 4M entries everyday with BigQuery, I thought that might be fairly expensive to do right? Or is this below a free tier?
[1] https://github.com/jstrieb/hackernews-button/actions/runs/61...
Querying that many entries processes (according to the BigQuery web interface) less than 300MB each time. Not sure how they arrive at that figure, but whatever. BigQuery has a free tier that includes up to 1TB/month of data processing. Since the Bloom filter is compiled once each day, I'm well under that limit.
I've tried to design the code so it shouldn't be too hard to do a drop-in replacement of Bloom filters with something else if a better data structure comes along.