ARCHIVED: Very happy with this tool, but I've stopped using it, especially because we have LLMs now.
StackOverflow Look Back Tool
🛠 Extract and search the posts you've up-voted on StackOverflow. Look back on your data.
Description
I need to quickly browse and re-learn from questions I've up-voted in the past. This is a browser extension and search UI
for doing that. See Background for more information.
NOTE: This project was developed on macOS. It is for my own personal use.
Design
The overall flow of the tool breaks down like this:
- Scrape your votes data from https://stackoverflow.com
- Expand the votes data into posts data using https://data.stackexchange.com
- View and search the posts
The application is made up of several distinct programs:
- A browser extension
- A search frontend
- This is implemented as a React application with NextJS.
- The code is in
search-ui/
- A search backend
- Algolia is used as the search back-end
- For local development and experimentation, these is also a Lucene-based web server in
search-api/.
This acts as a substitute for Algolia.
The source code of the browser extension is generally grouped by the execution context that the code runs in and is inviting
for future additions like Manifest V3 support, or a Safari browser extension.
util/
- Miscellaneous utility code that is not specific to the Look Back Tool.
src/
- The code in this directory is specific to the Look Back Tool.
src/web-page/
- The code in this directory runs on the web page.
src/backend/
- The code in this directory runs in the extension backend contexts: background workers, popups, and content
scripts.
src/chromium-manifest-v2/
- Code that supports a Manifest V2 web extension developed for Chromium browsers.
src/firefox-manifest-v2/
- Code that supports a Manifest V2 web extension developed for Firefox.
There is one library dependency for the extension: https://github.com/dgroomes/browser-extension-framework. The BrowserExtensionFramework
is an RPC-centric web extension framework that was originally developed as part of the Look Back Tool codebase.
The extension has been verified to work in the checked [x] browsers:
- Firefox (version 91)
- Chrome (version 103)
- Opera (version 78)
- Edge
- Safari
My Bias Against Content Scripts
In my opinion, content scripts are not compelling and I don't quite get their necessity in browser extension technical
architecture. From my perspective there of course needs to be one isolated JavaScript execution environment that powers
an extension. Why do there need to be two? The extension context has access to powerful browser APIs. The web page
itself is a powerful execution environment because it has access to the DOM and the application source code. So what is
the place of content scripts? I know by design, they have access to the DOM while the extension environment does not.
But why? I'm sure there are good reasons. But the three different exec environments and their unique capabilities and
restrictions has made it difficult to design and implement my own code.
My Bias for Web APIs
A corollary to my bias against content scripts is my bias for Web APIs. Most of the source code for this extension
actually executes on the web page, where standard Web APIs can be used. This code executes the domain logic like the
data scraping and HTML generation. As such, this code is perfectly portable to other "evergreen" browsers because it
just relies on standard web APIs instead of non-standard browser extension APIs (i.e. Manifest V2 and V3).
Instructions
Follow these instructions to install the tool as a Chrome browser extension and use it:
- Install npm
- Clone the BrowserExtensionFramework (BEF) Git submodule:
- Build the BEF distribution
- Follow the build instructions in the BEF README. It is located at
browser-extension-framework/README.md.
- Install BEF:
- Run the Webpack build:
- Build the extension distributions:
./build.sh
- This takes about a minute! I'm assuming the TypeScript type checking takes a lot of time.
- Open Chrome's extension settings page
- Open Chrome to the URL: chrome://extensions
- Alternatively, follow the instructions in the Firefox section below to install the extension in
Firefox
- Alternatively, follow the instructions in the Opera section below to install the extension in Opera
- Enable developer mode
- Enable the Developer mode toggle control in the upper right corner of the page
- Install the extension
- Click the Load unpacked button
- In the file finder window that opens, find the extension distribution
directory
build/chromium-manifest-v2-web-extension/, single click it to highlight it, and click the Select
button.
- It's installed!
- Open StackOverflow
- Log in
- Open your profile
- Click your picture in the top right corner to open your profile
- Open the "Votes" tab
- Scrape the votes data
- Open the extensions menu by pressing the puzzle icon in the top right of the window
- Alternatively, for Opera, it is a cube button
- Alternatively, for Firefox, there is NOT an extensions menu and instead you invoke the extension directly by
clicking a puzzle icon button on the right side of the URL bar.
- Click the "stackoverflow-look-back" extension entry
- A popup will show up with buttons titled "Scrape votes" and "Expand posts". Click "Scrape votes" and check the
console logs. The votes data will have been scraped and saved to browser storage.
- Expand the post data
- Go to the Stack Exchange Data Explorer
- If not logged in, then log in and navigate back to the original page.
- Repeat the earlier steps to open the extension entry
- The same popup will appear. Click "Expand posts". The post data will be expanded and saved into browser storage.
- Download the posts data
- While on the same StackExchange page, repeat the earlier steps to open the extension entry
- Click the "View posts" button
- Click the download button. Now, you have a copy of the data in a JSON file.
- Upload to Algolia
- You're on your own for this step. Algolia is really easy to use.
- Search the posts
- Follow the instructions in
search-ui to run the search UI.
- Finally, search for that one post you up-voted that has the magic incantation of code that you urgently need!
Firefox
The tool can also be installed as a web extension in Firefox! Follow these instructions to install it:
- Open Firefox to the debug page
- Load the plugin
- Click the button with the words Load Temporary Add-on…
- In the file finder window that opens, find the file
build/firefox-manifest-v2-web-extension/manifest.json and
click Open
- It's installed!
Opera
The extension can also run in Opera.
Follow these instructions to install it in Opera:
- Open Opera to the debug page:
- Enable developer mode
- Toggle on the Developer mode control in the top right corner
- Load the plugin
- Click the "Load unpacked" button
- In the file finder window that opens, find the directory
src/extension/chromium-manifest-v2 and click Select
- It's installed!
Wish List
General clean ups, TODOs and things I wish to implement for this project:
- Support the Edge browser. Write a Powershell script to build the extension distributions. This is the Windows friendly
thing to do. Add instructions as needed.
- Implement a "recents" feature? Maybe the most relevant StackOverflow posts are the ones I just added! I'm revisiting
them continually until I understand them (concepts) or memorize them (commands or code snippets).
- DONE Replace the viewer stuff with a standalone "Search UI". I've already implemented a good deal of this effort in
search-ui/.
It is a single-page app built with Next.js and the posts data lives in Algolia. The UI uses Algolia's sophisticated
component library. I'm impressed with the developer experience of Algolia (and I also notice the price tag $$$).
- Handle case insensitivity in the search result highlighting. Unfortunately I this means the algorithm has to be
changed considerably. Something to do with carrying a pair of "the original text section" and a "normalized
(lowercased) text section" and somehow preserving case in the original phrase. Maybe regex are the right choice but
then I have to escape the regexes if the matched term has regex special characters (which maybe they never do?).
- Facet search. Those are the clickable search categories you see in many search UIs.
- Show the question title.
- Give a visual indication that an entry is an answer to a question. Question entries, by contrast, will show
unadorned.
- Fix redundant calls to
toJSON. The whole purpose of that design is that it is called implicitly by the browser JSON.stringify
API.
- Consider what to improve about indexing
htmlBody. Unfortunately SEDE only provides the HTML body and doesn't have
an option for just the content. That's perfectly reasonable. But it's awkward to index the markup. Doesn't it have any
negative effect on search results? If not, then I can live with it. If I really wanted I could parse out the text nodes.
- Support an incremental scrap and incremental load from SEDE, and even incremental download to file... dang that's
kind of expensive. Maybe don't rush to do this.
- Get the answer's question title in the JSON data. Mostly this data is already there, but there are plenty of answers
I've upvoted where I didn't upvote the question. So, this has an effect on the SEDE part too.
Finished Wish List items
These are the finished items from the Wish List:
DONE Make an entrypoint.js file instead of re-using both scrape-votes.js and expand-posts.js independently
DONE Get more re-use out of code. For example, re-use the Votes class between the scrape votes functionality and
expand posts functionality
DONE Get post data for questions that were not up-voted but where there was an up-voted answer to that question. This
is a common case. I thought it was rare because I assumed that when I upvote an answer that I would have already
upvoted the question. But this isn't the case. I have a about two hundred of these cases. Also, even if I wanted to
up-vote the question, some are actually locked! For example, one of the very first things I wanted to search for in my
SO static data was for how to get the query parameters of the URL from JavaScript. But the question and answer didn't
show up because I didn't upvote the question, only the answer, and it turns out
the question itself is locked!
DONE Create a browser extension for this. The main benefit should be the removal of the manual steps like opening
three different web pages and moving the downloaded files to different directories.
DONE (Update I think it's a race condition with the JavaScript doc load order) There are some occasional caching
problems. Sometimes when I load a page, it saves "AppStorage" not define and stuff like that. I think it's a caching
problem because when I "hard reload and empty caches" it works. But then later it might fail again although I haven't
even changed the code so I don't understand how the cache could still be stale, and thus still be a problem. Not sure.
But it's annoying.
DONE Create a Chrome Manifest v2 extension. This would enable making a Firefox extension, which is still on v2 but is
working on supporting v3 sometime in 2022.
DONE Build a Firefox extension for the tool. For the most part, code can be re-used, but when it comes to the
extension APIs themselves, there are significant differences. In fact, porting the extension to Firefox has been one
of the most challenging software efforts I've done in recent years! In part, because I've been away from JavaScript
dev for so long but also because the standardization of extension APIs is still a work-in-progress.