[Browser Extension] Upload to Danbooru

Posted under General

Bookmarklet: the browser extension.

Feedback/suggestions are welcome.

Links

Usage

Context menu: right click on any image, select "Upload to Danbooru".
Page action: just visit any Danbooru-supported page, then click 📦 cardboard box icon in the address bar.

There is options page available, it can be accessed from the extension details page after install. You can set custom server url (e.g https://testbooru.donmai.us/) or change how upload page is opened.

Note: In Chrome page action is not in the address bar, it needs to be enabled by clicking 🧩 extensions icon to the right of the address bar and pinning it manually.
Note: Although this extension allows you to upload images from any website, you should be careful to not to upload image sample from sites not supported by Danbooru. List of the supported sites can be found here.

Permissions rundown

  • activeTab - access to the current tab, used to extract image/page urls and to detect gallery pages (executes simple script running document.querySelectorAll())
  • declarativeContent (Chrome only) - configure url matching rules for page action
  • contextMenus - create context menu entry
  • storage - store settings

Changelog

  • v1.0.0 (27.07.2020) - Proof of Concept.
  • v1.0.1 (28.07.2020) - Chrome support.
  • v1.1.0 (29.07.2020) - Better referrer extraction heuristics with fallback to old bookmarklet behavior in dire situations.
  • v1.1.1 (30.07.2020) - Version bump for addons.mozilla.org release.
  • v1.2.0 (18.08.2020) - Refactor, test coverage, add page actions.
  • v1.2.1 (18.08.2020) - Chrome support for page actions.
  • v1.2.2 (22.08.2020) - (Chrome) Use declarativeContent api for toggling page action (requires less dangerous permission, should improve performance), fix warnings.
  • v1.2.3 (02.09.2020) - (Chrome) Open tabs next to the current one in Chrome.
  • v1.2.4 (24.09.2020) - Fix twitter batch detection when quote with images is present (example tweet, thanks @BrokenEagle98 for pointing out).
  • v1.3.0 (12.12.2020) - Sync supported sites with latest Danbooru. Add batch support for Pixiv Fanbox and mobile Nijie.
  • v1.3.1 (09.05.2021) - Add page action for Skeb. Introduce url normalizers for bilibili, discord, pinterest, fantia and pixiv fanbox/boost CDN urls.
  • v2.0.0 (17.01.2022) - Add page actions for Foundation.app, Lofter and Plurk. Add batch support for Skeb and Pawoo. (Chrome) manifest v3. Migrated batch detection to content scripts instead of direct code execution.
  • v2.1.0 (23.01.2022) - (Internal) Batch detectors are now lazy-loaded. (Chrome) Extension no longer requests host permissions on install.
  • v2.1.1 (30.01.2022) - Experimental Firefox for Android support.
  • v2.1.2 (12.02.2022) - Fixed crash when opening upload url with empty (never saved) settings.
  • v3.0.0 (14.03.2022) - Removed batch detector feature (effectively deprecated by media assets). Referrer is no longer extracted through content script injection.
  • v3.0.1 (14.03.2022) - Improve referrer extraction heuristics.
  • v3.1.0 (16.03.2022) - Split settings for page action/context menu. Add placeholder for Danbooru URL in settings. Fix context menu setup in Firefox.
  • v3.2.0 (17.07.2022) - Make context menu entry toggleable from the settings. (Chrome) Drop declarativeContent permission. (Chrome) Open Danbooru upload page for unsupported schemes on page action click.
  • v3.3.0 (14.03.2023) - Add new page action matching rules for enty, picdig, baraag, bilibili, arca.live, fandom.com, 4chan, gelbooru/safebooru/rule34 and instagram. Add dark theme support in settings.
  • v3.3.1 (12.05.2023) - Add new page action matching rules for misskey (.io, .art, .design), update bilibili matching rules.
  • v3.3.2 (10.02.2024) - Add page action for bsky.app.
  • v3.3.3 (13.02.2024) - Add page actions for inkbunny, xfolio, ci-en, update page action matching rules for fanbox and weibo.
  • v3.3.4 (18.05.2024) - Update Twitter -> X links. Add page actions for patreon, opensea, e621, vk, medibang, behance, dotpict, foriio, galleria (emotionflow) and xiaohongshu.
  • v3.3.5 (20.05.2024) - Bring back Twitter links. Add Alt + Shift + D as a default shortcut for page action.
  • v3.4.0 (31.08.2024) - Add page actions for Reddit. Add logic to prevent uploads from Danbooru to Danbooru. Firefox extension migrated to Manifest V3.
  • v3.4.1 (31.08.2024) - Technical release to fix AMO warnings, no changes.
  • v3.4.2 (31.01.2026) - Improve Firefox for Android compatibility. Improve browser detection (see forum #414102). Add page actions for more misskey instances, grafolio, huajia (163), itaku and ko-fi.

Updated by ZipFile

Getting the following error when trying to load the unpacked extension on Chrome.

Failed to load extension
File
~\GitHub\Extensions\upload_to_danbooru
Error
Could not load icon 'icons/icon16.png' specified in 'page_action'.
Could not load manifest.
System
  • OS: Windows 8.1 (64-bit)
  • Browser: Chrome 84.0.4147.125 (Official Build) (64-bit) (cohort: Stable)
  • Extension: upload_to_danbooru-1.2.1-chrome.zip
Edit:

This issue has been resolved. It was a PEBKAC error.

Updated by BrokenEagle98

Danbooru does not support bookmarklet uploads from bilibili (aside from direct links) atm. Ideally it should be implemented Danbooru-side first.

But otherwise for t.bilibili.com (like post #4498750), probably yes. Normalizing url looks trivial enough. For videos and manga - unlikely.

I encountered 2 errors when trying to load version 2.0.0 on Chrome.

1. Unrecognized manifest key

https://cdn.discordapp.com/attachments/618878216815247372/933063232107741184/unknown.png

After I deleted that manifest key, I tried it again but encountered the next error.

2. Cannot read properties of undefined

https://cdn.discordapp.com/attachments/618878216815247372/933063524555558953/unknown.png

Edit:
  • (2022-01-18)
    • ZipFile added upload_to_danbooru-2.0.0-chrome.zip to the release which fixed the issue.

Updated by BrokenEagle98

For what it's worth, the extension still works on Microsoft Edge 143.0.3650.96 (there's an update available but I haven't updated it yet, I scarcely restart due to how many tabs I have open). Someone else said the extension wasn't working for them (Google Chrome) so I figure I would ask how is it not working. If it's just the context menu, you can disable it and then reenable it to get it back. For other issues, try reinstalling, possibly a few times.

nonamethanks said in forum #414103:

Works for me. What browser version?

Brave v1.86.139.

WRS said in forum #414186:

For what it's worth, the extension still works on Microsoft Edge 143.0.3650.96 (there's an update available but I haven't updated it yet, I scarcely restart due to how many tabs I have open). Someone else said the extension wasn't working for them (Google Chrome) so I figure I would ask how is it not working. If it's just the context menu, you can disable it and then reenable it to get it back. For other issues, try reinstalling, possibly a few times.

It's not just the context menu, even the page action doesn't work.

The reason the extension has broken on Brave, is that Brave defines globalThis.browser and globalThis.chrome. Chrome only defines the latter, so the extension uses the former to detect whether it's running in a Firefox environment. This means in Brave, the extension thinks it's installed in a Firefox browser, but Brave is actually a Chrome-based browser, leading to errors it tries to use Firefox-specific APIs that aren't available in Brave.

I'll report it as an issue on the github.

bipface said in forum #414502:

The reason the extension has broken on Brave, is that Brave defines globalThis.browser and globalThis.chrome. Chrome only defines the latter, so the extension uses the former to detect whether it's running in a Firefox environment. This means in Brave, the extension thinks it's installed in a Firefox browser, but Brave is actually a Chrome-based browser, leading to errors it tries to use Firefox-specific APIs that aren't available in Brave.

I'll report it as an issue on the github.

Huh. I've been using it fine on Brave up until a few days ago. Is this a new change on Brave's end? The current version dates to January 15.

Oh, now I see what people mean - it just absolutely does nothing at all once you've updated your browsers. The extension stopped working for me now because my PC and Microsoft Edge force updated. The same issue affecting Brave might be affecting Microsoft Edge - not functional on 144.0.3719.82.

ETA: I fixed it myself for now by referencing what bipface posted above and removed Firefox detection altogether, then built the extension from the modified source and loaded the built extension into Microsoft Edge. To break it down clearly:

  • Download the GitHub repository and unzip it.
  • Open a code editor of your choice and remove the offending bit that bipface identified as Firefox detection, as below.
if (ctx.browser) {
    // firefox
    return [ctx.browser, false, !ctx.browser.contextMenus];
}
  • Follow the build steps in the README of the repository. npm i -> npm run buildChrome.
  • Enable developer mode on Microsoft Edge, pick Load Unpacked in Manage extensions and select the dist folder.
    • The dist folder is created from the build command and put in with the source code files you downloaded from GitHub.
  • There's your fix for now until the extension itself is actually updated.

Updated by WRS

1