Edit with Caboodle

Put an Edit with Caboodle button by a file on your website. The file opens in the right Caboodle program in a new window; when the person presses Save to your site, the edited file comes back to your page, and you store it where you store your files.

One script, no API key, no Caboodle account, no server work on either side: the file is handed over inside the browser with postMessage and never goes through Caboodle’s servers. This page is written so that a developer – or a coding agent – can build the integration from it alone.

Before you start

  1. Any https site can use it – no sign-up, no key. Plain http works only on localhost and 127.0.0.1 (any port), for building and testing. Caboodle always shows your real address beside the name you give (“Editing robot.glb for GamerFuel (gamerfuel.com)”). Sites that misuse it can be blocked.
  2. Load the script from Caboodle: <script src="https://caboodle.tools/edit.js"></script>. If your site has a Content-Security-Policy, add https://caboodle.tools to script-src.
  3. Don’t send Cross-Origin-Opener-Policy: same-origin on the page with the button: it cuts the link to the window it opens, so the file can’t be handed over or come back. No COOP header, unsafe-none or same-origin-allow-popups are fine.
  4. Call Caboodle.edit() straight from the click, before any await – browsers block windows opened later. Don’t fetch the file first: pass its URL (or a promise) and the window opens at once while the file follows.
  5. The page that opened Caboodle has to stay open until the person saves: that’s where the file comes back. Don’t navigate away from it in the meantime (open it in a modal or keep the person on the page).

Quick start

<button id="edit-robot">Edit with Caboodle</button>
<script src="https://caboodle.tools/edit.js"></script>
<script>
  document.getElementById('edit-robot').addEventListener('click', () => {
    Caboodle.edit({
      file: '/assets/robot.glb',          // its URL on your site (or a Blob, or a promise of one)
      name: 'robot.glb',                  // the extension picks the program
      site: 'GamerFuel',                  // the button in Caboodle says “Save to GamerFuel”
      onSave: async (blob, name) => {     // the edited file
        const r = await fetch('/api/assets/robot.glb', { method: 'PUT', body: blob });
        if (!r.ok) throw new Error('Upload failed (' + r.status + ')');   // shown in Caboodle
      },
    });
  });
</script>

That’s all. The person edits, presses Save to GamerFuel (or Ctrl+S / ⌘S), your onSave runs, and Caboodle shows “Saved to GamerFuel” – or your error, if onSave throws. They can save as many times as they like; each save calls onSave again.

Reference: Caboodle.edit(options)

OptionTypeWhat it is
fileBlob · File · string · Promise<Blob> · () => Promise<Blob>Required. The file. A string is fetched from your page with fetch(url) (same-origin cookies are sent; for another origin it needs CORS). A promise or function lets you fetch it your own way (e.g. with an auth header) – the window opens first and waits.
namestringThe file’s name with its extension, e.g. robot.glb. Required unless file is a File or a URL ending in the name. The extension picks the program (see file types); the name is shown to the person and comes back with the edited file.
sitestringYour site’s name, on the Save button and in messages (“Save to GamerFuel”). Default: your hostname without www.
formatstringWhat should come back, as an extension, e.g. 'glb'. Default: the same kind as went in (a .glb comes back a .glb). If the program can’t write it, it uses its first format and says so.
programstringOverrides the program the extension picks: sprite (a .png sprite sheet in the Sprite editor – see sprite sheets), graphics, image, spreadsheet, document, pdf, slides, wireframe, mindmap, midi, video, audio, text.
dataBlob · string · Promise<Blob> · () => Promise<Blob> · objectOptional, with program: 'sprite': the sheet’s frames and animations as an Aseprite JSON. Taken like file (a string is its URL); a plain object is sent as JSON. Its frames and animations are what the sheet opens with. Without it, the frames are found as for any PNG (the grid Caboodle keeps inside its PNGs, else from the picture).
styleobjectOptional, with program: 'sprite': the game’s art style – { unit, view, palette, description }, every field optional.
referencesarrayOptional, with program: 'sprite': up to 5 sheets of the game to look at – [{ name, file, data }], file and data taken like the options of those names. Read-only in Caboodle and never sent back. One that can’t be fetched is left out (a warning in the console); the rest still open.
sheetsarrayOptional, with program: 'sprite': up to 100 more sheets to edit in the same window – [{ name, file, data }], file and data taken like the options of those names, each name a file name used once (e.g. goblin.png; a name used twice: only its first). Each opens as a sheet of its own beside the one in file and comes back on every save in extra.sheets with that name and opened: true. One that can’t be fetched stops the whole open, like file (onError).
titlestringOptional: the file’s title in Caboodle, shown to the person (“Editing title for GamerFuel”). Default: name without its extension.
reskinstringOptional, with program: 'sprite': a suggested prompt for Reskin with AI. The window opens with it as soon as the sheets are in, every sheet sent ticked and your references as its style pictures (Style from, so the reskin matches them), for the person to change or run – nothing is made until they press Reskin. Up to 4000 characters. %asset_name% in it becomes each sheet’s name when it’s made: its asset, else its file name without the ending, dashes as spaces – so one prompt works for several sheets.
assetstringOptional, with reskin: the file’s name for %asset_name% ('Enemy robot'); each of sheets may have its own asset too. Up to 100 characters.
onSaveasync (blob, name, extra) => voidThe edited file and its name (the original name with the format’s extension, e.g. robot.glb). From the Sprite editor, extra.data is the sheet’s Aseprite JSON (a Blob, application/json) and extra.sheets the other sheets – those you sent in sheets (opened: true) and those made in the window – [{ name, blob, data, opened? }] (see below). From the MIDI editor with format mp3 or wav, extra.data is the song’s notes as a .mid (a Blob, audio/midi): keep it to open the song in the MIDI editor again later, while you play the sound. For other programs extra is {}. Store it. Resolve when it’s stored; throw (or reject) to tell the person it wasn’t – the error’s message is shown in Caboodle. Caboodle waits up to 10 minutes for it.
onClose() => voidOptional. The Caboodle window was closed (checked about once a second).
onError(error) => voidOptional. The file couldn’t be fetched or awaited; the Caboodle window is closed again. Default: logged to the console.

Returns { window, close() }: the Caboodle window, and a function that closes it.
Throws right away when an option is wrong, the file type isn’t one Caboodle opens, or the browser blocked the window (“call it from a click”).
Caboodle.origin is 'https://caboodle.tools'; set it to point at another copy of Caboodle (for Caboodle’s own testing).

File types

Your fileOpens inCan come back as (format)
.glb .gltf .obj .stl .ply .fbx3D Graphicsglb gltf obj stl ply
.png .jpg .jpeg .webp .gif .bmp .psdImage editorpng jpg webp psd (a GIF or BMP comes back as PNG)
.png with program: 'sprite' (and its .json as data)Sprite editorpng – with its frames and animations as Aseprite JSON in extra.data
.xlsx .xlsm .xltx .xls .csv .tsvSpreadsheetxlsx csv tsv
.docx .doc .md .html .htmWord processordocx html txt (a .md comes back as .docx)
.pdfPDF editorpdf txt
.pptx .pptSlide showpptx pdf
.excalidraw .drawio .bmmlWireframeexcalidraw drawio bmml svg pdf png
.xmind .mm .opmlMind Mapxmind mm opml md txt svg pdf png
.mid .midi .karMIDI editormid mp3 wav – an MP3 or WAV with the song’s .mid in extra.data
.mp4 .mov .m4v .webm .mkvVideo editormp4 webm
.mp3 .wav .m4a .aac .ogg .oga .opus .flacAudio editormp3 m4a wav webm
.txt .json .js .ts .css .xml .yml .md … and other textText editor (program: 'text' for .md/.html)the file as it came, in its encoding and line endings

Sprite sheets

A .png opens in the Image editor and comes back as a flat picture. With program: 'sprite' it opens in the Sprite editor, cut into its frames, and comes back with them:

Caboodle.edit({
  program: 'sprite',
  file: '/assets/hero.png',
  data: '/assets/hero.json',             // its Aseprite JSON (optional)
  name: 'hero.png',
  site: 'GamerFuel',
  onSave: async (png, name, extra) => {   // name: 'hero.png'
    await upload(name, png);
    await upload('hero.json', extra.data); // the frames and animations, as Aseprite JSON
  },
});

The game’s style, references, and new sheets

Caboodle.edit({
  program: 'sprite', file: '/assets/hero.png', data: '/assets/hero.json', name: 'hero.png', site: 'GamerFuel',
  style: {
    unit: 32,                                  // the game’s tile, in px
    view: 'side',                              // 'side' (a platformer) · 'top' (top-down) · 'iso' (isometric)
    palette: ['#1a1c2c', '#5d275d', '#b13e53'],  // up to 64 colours, '#rrggbb'
    description: '16-colour pixel art, dark 1 px outlines, light from the top left',   // up to 1000 characters
  },
  references: [                                // up to 5, to look at
    { name: 'tiles.png', file: '/assets/tiles.png', data: '/assets/tiles.json' },
  ],
  onSave: async (png, name, extra) => {
    await upload(name, png, extra.data);                                    // the sheet that was opened
    for (const s of extra.sheets) await upload(s.name, s.blob, s.data);      // e.g. 'slime.png' and its JSON
  },
});

Several sheets in one window

Caboodle.edit({
  program: 'sprite', site: 'GamerFuel',
  file: '/assets/hero.png', data: '/assets/hero.json', name: 'hero.png',   // the first
  sheets: [                                    // up to 100 more, each its own sheet in the same window
    { name: 'goblin.png', file: '/assets/goblin.png', data: '/assets/goblin.json' },
    { name: 'troll.png', file: '/assets/troll.png', data: '/assets/troll.json' },
  ],
  title: 'Winter · 3 sheets',                  // the file's title in Caboodle
  onSave: async (png, name, extra) => {
    await upload('hero.png', png, extra.data);
    for (const s of extra.sheets) {
      if (s.opened) await upload(s.name, s.blob, s.data);   // 'goblin.png', 'troll.png': the names you gave
      else await uploadNew(s.name, s.blob, s.data);          // a sheet made in the window
    }
  },
});

Importing sheets from Caboodle: Caboodle.pick(options)

The other way round: the person’s own sprite sheets, already in Caboodle, brought to your site. A Caboodle window lists their sprite files (those in this browser, and – signed in – those in their cloud), newest first, with a search box; a file opens to its sheets (a picture, frames, frame size, hit area); they tick any number, from any files (a file’s own tick takes all its sheets), and press Send to GamerFuel. They can send more than once from the same window.

button.onclick = () => Caboodle.pick({   // from the click itself
  site: 'GamerFuel',
  program: 'sprite',
  title: 'Import into Tiles',                // optional: shown at the top of the window
  onPick: async (sheets) => {               // [{ name: 'slime.png', blob, data, file: { id, title }, sheet: { id, name } }]
    for (const s of sheets) await upload(s.name, s.blob, s.data);
  },                                         // throw to say they weren't taken – the message is shown in Caboodle
  onClose: () => {},
});

Each sheet comes as on a save: blob its PNG (the grid inside it), data its Aseprite JSON (frames, frameTags, the hit slice when it has a hit area), name the sheet’s name with .png – never the same as another in the same batch (a second “slime” is slime 2.png) – and where it came from. Messages: caboodle:ready → you: { t: 'caboodle:pick-open', session, site, title, format?, v: 2 } → Caboodle, on Send: { t: 'caboodle:picked', session, sheets } → you: caboodle:saving at once and caboodle:saved when stored, as for a save (the page is sprite.html?pick=<session>&from=<your origin>).

Whole files from other programs

Any other program that can save back to your site (see file types) can be picked from too: the window lists the person’s files of that program, they tick any number and press Send. Each is opened in that window and written as a save writes it, in the format you ask for. From the MIDI editor with format: 'mp3' (or 'wav'), data is the song’s notes as a .mid.

button.onclick = () => Caboodle.pick({
  site: 'GamerFuel',
  program: 'midi',                           // or 'audio' – the person's songs, or sound projects
  format: 'mp3',
  onPick: async (files) => {                // [{ name: 'Theme.mp3', blob, data (the .mid), file: { id, title } }]
    for (const f of files) await upload(f.name, f.blob, f.data);
  },
});

What the person sees

  1. A new window (or tab) with the program and the file, and a strip: “Editing robot.glb for GamerFuel (gamerfuel.com) – Save to GamerFuel (Ctrl+S) sends it back”. The address in brackets is always your page’s real one.
  2. A Save to GamerFuel button on the top bar. Ctrl+S / ⌘S does the same. Download still works too.
  3. Saving shows “Sending…”, then “Saved to GamerFuel”, or “Not saved to GamerFuel: your error”.
  4. If your page was closed, the strip says so and Save offers to download the file instead.

The file becomes a file of the person’s in Caboodle: kept in that browser (so a reload doesn’t lose the work) and, if they’re signed in to Caboodle, in their Caboodle cloud once they change it – so they can share it, work on it with others or have Claude change it (those changes come into the open window, and Save sends them to you). For a site Caboodle trusts it goes to their cloud at once. No sign-in is needed to edit and save back. Sounds and videos are copied into the editor first, and the person picks a quality for that copy (original quality needs a paid Caboodle account).

Fuller examples

Plain JavaScript, with your own auth and a busy state

function editWithCaboodle(asset, button) {
  // asset: { id, name, url } from your own data
  const handle = Caboodle.edit({
    // fetched your way (here with a token); the window opens first and waits for it
    file: () => fetch(asset.url, { headers: { Authorization: 'Bearer ' + token } })
      .then((r) => { if (!r.ok) throw new Error('Couldn’t load ' + asset.name); return r.blob(); }),
    name: asset.name,
    site: 'GamerFuel',
    onSave: async (blob, name) => {
      const form = new FormData();
      form.append('file', blob, name);
      const r = await fetch('/api/assets/' + asset.id + '/versions', { method: 'POST', body: form, headers: { Authorization: 'Bearer ' + token } });
      if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error || 'Upload failed');
      refreshAsset(asset.id);              // show the new version on your page
    },
    onClose: () => { button.disabled = false; button.textContent = 'Edit with Caboodle'; },
    onError: (err) => { button.disabled = false; alert(err.message); },
  });
  button.disabled = true;
  button.textContent = 'Editing in Caboodle…';
  return handle;
}

React

// once, e.g. in your root layout:  <script src="https://caboodle.tools/edit.js" async />
// (with Next.js: <Script src="https://caboodle.tools/edit.js" strategy="afterInteractive" />)

export function EditWithCaboodle({ asset, onSaved }) {
  const [editing, setEditing] = useState(false);
  const open = () => {
    // no await before this line: the window must open in the click
    window.Caboodle.edit({
      file: asset.url,
      name: asset.name,
      site: 'GamerFuel',
      onSave: async (blob, name) => {
        await uploadAssetVersion(asset.id, blob, name);   // your API; throw on failure
        onSaved?.();
      },
      onClose: () => setEditing(false),
      onError: (e) => { setEditing(false); console.error(e); },
    });
    setEditing(true);
  };
  return <button onClick={open} disabled={editing || !window.Caboodle}>
    {editing ? 'Editing in Caboodle…' : 'Edit with Caboodle'}
  </button>;
}

TypeScript

declare global {
  interface Window {
    Caboodle: {
      origin: string;
      edit(o: {
        file: Blob | string | Promise<Blob> | (() => Promise<Blob>);
        name?: string;
        site?: string;
        format?: string;
        program?: 'sprite' | 'graphics' | 'image' | 'spreadsheet' | 'document' | 'pdf' | 'slides' | 'wireframe' | 'mindmap' | 'midi' | 'video' | 'audio' | 'text';
        data?: Blob | string | Promise<Blob> | (() => Blob | Promise<Blob>) | object;   // with program: 'sprite'
        style?: { unit?: number; view?: 'side' | 'top' | 'iso'; palette?: string[]; description?: string };   // with program: 'sprite'
        references?: { name: string; file: Blob | string | Promise<Blob> | (() => Blob | Promise<Blob>); data?: Blob | string | Promise<Blob> | (() => Blob | Promise<Blob>) | object }[];   // at most 5
        sheets?: { name: string; file: Blob | string | Promise<Blob> | (() => Blob | Promise<Blob>); data?: Blob | string | Promise<Blob> | (() => Blob | Promise<Blob>) | object }[];   // at most 100, to edit
        title?: string;
        onSave?: (blob: Blob, name: string, extra?: { data?: Blob; sheets?: { name: string; blob: Blob; data: Blob; opened?: true; from?: string }[] }) => void | Promise<void>;   // data: a sheet’s JSON, or a song’s .mid
        onClose?: () => void;
        onError?: (error: Error) => void;
      }): { window: Window; close(): void };
    };
  }
}
export {};

Good to know

Testing

  1. Run your site on http://localhost:<any port> – it’s allowed against caboodle.tools, so you can build before going live.
  2. Click the button: Caboodle opens with the file and the “Editing … for site” strip.
  3. Change something, press Save to site: onSave gets a Blob of the right type, and Caboodle says “Saved to site”.
  4. Make onSave throw: Caboodle shows your message.
  5. Close your page, then Save in Caboodle: it offers Download. Close Caboodle: onClose runs.
  6. Automated tests: open your page in a real browser (Playwright, Puppeteer); the click has to be a real one (page.click) for the window to open, and the new window is a new page/target.

A working stand-in site: examples/edit-with-caboodle.html (pick any file) – its source is examples/edit-with-caboodle.js, and the script itself is edit.js (about 130 lines, readable).

If something doesn’t work

You seeWhy, and what to do
“the browser blocked the window – call it from a click”Caboodle.edit ran after an await or a timer. Call it first thing in the click handler; pass the file as a URL, promise or function.
“site can’t open files in Caboodle – only https sites can”Your page is on plain http somewhere other than localhost. Serve it over https.
“…but that page isn’t there – open it again from the site”Caboodle has no link back to your page: the page sent Cross-Origin-Opener-Policy: same-origin, the window was opened with noopener, or the link was copied into a new tab. Use Caboodle.edit and drop that COOP value.
Caboodle stays on “Opening a file from …”The file hasn’t arrived: your file promise is still pending, or the fetch failed (then onError runs). Check the URL and CORS.
“Caboodle.edit: Caboodle doesn’t open …”The extension isn’t in the table. Give name the right extension, or pass program.
“Not saved to site: …”Your onSave threw; the rest is your message.
The script doesn’t loadYour Content-Security-Policy: add https://caboodle.tools to script-src.

The messages (without edit.js)

edit.js is the supported way. If you’d rather speak to Caboodle yourself:

  1. Open https://caboodle.tools/<page>?edit=<session>&from=<your origin, URL-encoded> with window.open (not noopener). <page> is sprite.html, graphics.html, image.html, spreadsheet.html, document.html, pdf.html, slides.html, wireframe.html, mindmap.html, midi.html, video.html, audio.html or text.html; <session> is 8–40 characters of a–z 0–9, new each time.
  2. Caboodle → you: { t: 'caboodle:ready', session } when it’s ready.
  3. You → Caboodle: { t: 'caboodle:open', session, file: Blob, name, format, site, data?: Blob, style?, references?, sheets?, title?, v?: 2 }, with targetOrigin 'https://caboodle.tools'. For sprite.html: data the sheet’s Aseprite JSON, style { unit, view, palette, description }, references [{ name, file: Blob, data?: Blob }] (at most 5), sheets [{ name, file: Blob, data?: Blob }] (at most 100, to edit).
  4. Caboodle → you, on each save: { t: 'caboodle:save', session, blob, name, data?: Blob, sheets? } – from sprite.html: data the sheet’s Aseprite JSON, sheets [{ name, blob: Blob, data: Blob, opened?: true, from?: string }], the sheets you sent (opened, by their names) and those made in the window (from: the sheet sent that a reskin or recolour was made from); from midi.html with format mp3 or wav: data the song’s .mid.
  5. You → Caboodle, at once: { t: 'caboodle:saving', session } (if your caboodle:open said v: 2 – then, without it within a few seconds, Caboodle tells the person your page was reloaded or left and offers the file as a download), and when it’s stored: { t: 'caboodle:saved', session, ok: true } or { …, ok: false, error: 'message' }.

Accept messages only where event.origin === 'https://caboodle.tools', event.source is the window you opened and session is yours. Caboodle does the same the other way round.

Questions, or a site to add: hello@caboodle.tools · About Caboodle