Skip to content

Instantly share code, notes, and snippets.

@phette23
Created March 1, 2023 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/0052439c56770b0d178df647ca00162d to your computer and use it in GitHub Desktop.
Save phette23/0052439c56770b0d178df647ca00162d to your computer and use it in GitHub Desktop.
select all checkboxs on chrome's history page chrome://history
document
.querySelector('history-app').shadowRoot
.querySelector('history-list').shadowRoot
.querySelectorAll('history-item').forEach((hi, i) => {
const cbox = hi.shadowRoot.querySelector('cr-checkbox')
// merely setting checked = true doesn't work, chrome wants you to click them
if (!cbox.checked) cbox.click()
})
@phette23
Copy link
Author

phette23 commented Mar 1, 2023

Inexplicably, Chrome's history page chrome://history has no "select all" check box so you can't, for instance, search for a particular site then delete all the matching history items for just that site. This means you sometimes have to click dozens of checkboxes to remove portions of your browsing history. It would be simple to use the browser's JavaScript console to work around this, except that the history page uses web components and custom tags like history-list and history-item which use the Shadow DOM and cannot be selected with a straightforward document.querySelectorAll('cr-checkbox').

So after a lot of trial and error, I figured out how to traverse down through the nested shadow DOMs to click every page's check box (<cr-checkbox> tag). You should be able to open the JS console (⌘ + Option + J on Mac), copy-paste this code in, press enter/return to execute it, and select everything. Note that Chrome's history app is an infinite scroll so searching for a site and then running this snippet won't necessarily remove all its entries, only the visible ones that have loaded, but you could scroll for a while to load everything fist before using the snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment