Skip to content

Instantly share code, notes, and snippets.

@vibol
Created February 21, 2018 21:25
Show Gist options
  • Save vibol/70b7545db3d4c76b55da0dbea266e1aa to your computer and use it in GitHub Desktop.
Save vibol/70b7545db3d4c76b55da0dbea266e1aa to your computer and use it in GitHub Desktop.
Google Docs: A Google App script for deleting all bookmarks from a Google Doc
// 1. Tools > Script editor...
// 2. Paste the below code
// 3. Run
// 4. Approve permissions
// 5. Go to the document from which Script editor was launched and allow the script to run
function deleteAllBookmarks() {
var ui = DocumentApp.getUi();
var response = ui.alert('This will delete ALL bookmarks in this document. Are you sure you want to continue?', ui.ButtonSet.YES_NO);
if (response == ui.Button.YES) {
var doc = DocumentApp.getActiveDocument();
var bookmarks = doc.getBookmarks();
for (var i = 0; i < bookmarks.length - 1; i++) {
bookmarks[i].remove();
}
}
}
@jmcmurry
Copy link

jmcmurry commented Apr 2, 2023

The .remove() method is definitely the correct method according to the api docs, however, it no longer seems to work. I filed an issue here https://issuetracker.google.com/issues/276617142

@cstanze
Copy link

cstanze commented May 5, 2023

This script also works in the console; however, you may need to scroll through multiple pages to ensure they're all removed.

document.querySelectorAll('.kix-bookmarkicon-icon-outer').forEach(el => {
    try {
        let ev = getEventListeners(el)
        ev.mousedown[0].listener(el)
        ev.mousedown[1].listener(el)
        document.querySelectorAll('.kix-bookmark-bubble-button[data-tooltip="Remove"]').forEach(_ => _.click())
    } catch (error) {
        console.log("error on el: ", el) // likely means scrolling, can i automate this?
    }
})

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