How I Built a Zero-OAuth Google Photos Bulk Cleaner in Vanilla JS (Virtual Scroll & DOM Pitfalls)
π Free Lifetime Pro for the First 199 DEV Readers! Get a Free Pro Code: Email [email protected] (subject: PhotoSweep Pro) β the first 199 readers get a free Lifetime Pro activation code (no strings attached). Try It
π Free Lifetime Pro for the First 199 DEV Readers!
- Get a Free Pro Code: Email [email protected] (subject:
PhotoSweep Pro) β the first 199 readers get a free Lifetime Pro activation code (no strings attached).- Try It on Edge: PhotoSweep on Microsoft Edge Add-ons | Homepage
- Feedback Welcome: If you find it useful, an honest review on the Edge Store would help a solo dev a ton! If anything feels clunky or missing, drop a comment below with your feature request or bug report and I'll fix/build it ASAP.
A few weeks ago, my Google account hit the dreaded 15GB storage limitβto the point where Gmail started warning me that incoming emails would bounce.
I opened Google Photos to clean up years of old screenshots, blurry bursts, and huge videos, and immediately remembered why everyone dreads this:
- Google Photos still has no native "Select All" button for an entire library.
- Holding
Shiftto select thousands of items breaks as soon as the virtualized grid unmounts earlier DOM nodesβeither the tab freezes or one accidental misclick wipes your entire selection. - Most existing bulk-delete extensions are years old, break on non-English Google Photos interfaces, or start deleting immediately without letting you preview what's selected.
And you can't solve this cleanly with the official Google Photos Library API eitherβthe API doesn't even allow deleting photos that weren't uploaded by your own app, plus requesting Google OAuth scopes raises obvious privacy concerns.
So I built PhotoSweep, a lightweight, 100% local Manifest V3 extension in plain Vanilla JS + CSS with zero backend and zero Google OAuth. It just went live on the Microsoft Edge Add-ons Store.
Here are the 4 trickiest DOM engineering pitfalls I ran into while automating photos.google.comβhopefully useful if you ever build a browser extension on top of Google's Closure/Wiz web apps.
1. Finding the Real Virtual Scroll Container (Not window)
Google Photos doesn't scroll window. The photo grid lives inside a nested scrollable container under c-wiz[role="main"].
If you blindly scroll the first overflow-y: auto element you find, you'll end up scrolling the left navigation sidebar instead of the photo feed. I ended up filtering candidate scroll containers by bounding-box dimensions (width & height thresholds) and driving virtual list hydration with a combination of scrollBy, scrollIntoView, and WheelEvent.
Detecting true end-of-library (versus "still lazy-loading") also required checking three signals together:
- Scroll offset delta;
- The timeline scrubber
[role="slider"](aria-valuenow); - Whether any new
a[href*="/photo/"]nodes appeared in the DOM.
2. Invisible opacity: 0 Checkboxes & Date-Header Collisions
Two subtle checkbox traps bit me early on:
-
Un-hovered checkboxes have
opacity: 0: Every photo's[role="checkbox"]is hidden until hover, so standard "is element visible?" checks skip them completely. -
Date-header "Select entire day" checkboxes: Each date group has its own checkbox next to the date heading (
h2/h3). If your script clicks one of those by accident, it selects an entire day at once and throws off your batch counter. Filtering them out viaaria-labelpatterns and parent heading checks fixed it cleanly.
3. Google's jsaction Event Pipeline Ignores Plain .click()
Google Photos relies heavily on Google's jsaction event delegation. Calling el.click() alone intermittently fails to trigger selection or toolbar actions.
Dispatching the full pointer + mouse sequence solved the flakiness:
pointerdown -> mousedown -> pointerup -> mouseup -> click
Pairing this with configurable click delays (100msβ500ms) and batch sizes (25 / 50 / 100) keeps the tab smooth even on libraries with tens of thousands of photos.
4. Multi-Language Trash Detection (3-Layer Fallback)
A huge complaint about older cleaners is: "Doesn't work because my Google Photos is in Spanish / Japanese / Chinese."
Instead of relying on English text alone, PhotoSweep uses a 3-layer fallback to trigger "Move to Trash":
-
Layer 1: Built-in
aria-label/data-tooltipdictionary covering 11+ languages (EN, ZH, ES, FR, DE, JA, KO, PT, RU, IT, etc.). -
Layer 2: Matching the Material Trash icon's SVG
pathsignature in the top action bar. -
Layer 3: Dispatching Google Photos' native keyboard shortcut (
#/Delete).
For the confirmation modal, the script polls for up to 3 seconds matching data-mdc-dialog-action="ok" or localized confirmation labels. If no dialog appears, it automatically pauses so nothing runs out of sync.
Safety First (Dry-Run by Default)
Nobody trusts an automation tool near years of family photosβmyself included. So PhotoSweep enforces a few guardrails:
- Starts in Dry-Run (Select Only) mode by default: It highlights selected items with a blue border and never clicks delete until you explicitly switch to "Auto Move to Trash".
- Trash only (30-day recovery): Items are only moved to Google Photos Trash, never permanently wiped.
- Skip Starred / Cutoff Year: Automatically skips favorited photos by default, and lets you set a cutoff year (e.g., 2024 & Older) so recent photos stay untouched.
-
100% Local: Only requests
storage,activeTab, andhttps://photos.google.com/*. No photos, credentials, or metadata ever leave your browser.
(Quick reminder if you try it: if mobile backup & sync is turned on in your phone's Google Photos app, deleting cloud photos may also delete synced local copies on your phoneβturn off backup first if you only want to free cloud storage.)
Try It Out & Free Pro Giveaway (First 199 Readers!)
- Edge Add-ons Store: PhotoSweep on Microsoft Edge Add-ons
- Landing Page & Privacy Policy: https://qzm12348.github.io/photosweep/
It includes 500 free items per day (resets daily at midnight, with all filters, Dry-Run, and Skip Starred unlocked), plus an optional $4.99 one-time lifetime Pro unlock if you want to wipe tens of thousands of old photos in one sitting.
π DEV Community Early-Bird Giveaway: To celebrate the launch, I'm giving away free Lifetime Pro promo codes to the first 199 readersβno strings attached! Just email me at [email protected] (subject: PhotoSweep Pro) and I'll reply with your free activation code.
If you give PhotoSweep a spin and find it genuinely helpful, leaving an honest review on the Microsoft Edge Add-ons Store would mean the world to a solo indie dev. And since Google occasionally tweaks Google Photos' DOM structure, feel free to drop any bugs or edge cases in the comments belowβI'll fix them ASAP!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.