← Back to the site

Plugins Better GrokBot

A plugin adds a small tool in the Plugins tab: a counter, standard responses, a timer, a call to a public API... It is written in JavaScript, in a single file, and is shared as a package.

Safety, first

Structure of a plugin

mon-outil/
  plugin.json   (obligatoire)
  main.js       (obligatoire)
  icon.png      (facultatif : png, svg, jpg ou webp, 96 Ko au plus)
  README.md     (facultatif)

The manifesto plugin.json

{
  "manifest": 2,
  "id": "mon-outil",
  "name": "Mon outil",
  "version": "1.0.0",
  "description": "Ce que fait le plugin, en une phrase.",
  "author": "Votre nom ou pseudo",
  "icon": "🧩",
  "main": "main.js",
  "permissions": ["notify", "storage"],
  "hosts": [],
  "minVersion": "1.5.0",
  "homepage": "https://exemple.org"
}
Field Ruler
manifest Always 2.
id Lowercase letters, numbers and hyphens, without hyphens at the beginning or end. Example: mon-outil. It must be unique.
name Name displayed.
version Format 1.0.0. A higher version replaces the old one upon import.
icon An emoji, or the name of an image file in the package.
permissions List among those below. Nothing else is accepted.
hosts Sites reachable with permission net (https only).

Permissions

Permission What it allows
notify Show a notification in Better (bg.ui.toast).
composer.read Read the text you type in Grok.
composer.write Write to the message field of Grok, without sending it.
thread.read Read the open conversation.
storage Keep your own data (256 KB, isolated from other plugins).
clipboard.write Copy text to clipboard.
net Call the sites listed in hosts, using https. Local addresses refused, 1 MB per response, without cookies.

Ask as little as possible: the import screen shows each permission before installation.

The bg API

Your main.js receives an object bg. The code can use await directly.

bg.app            // { version, lang, locale }
bg.plugin         // { id, version, permissions }
bg.pick({ fr: "Bonjour", en: "Hello" })   // texte dans la langue de l'app

bg.ui.render([ ...éléments ])   // dessine le panneau
bg.ui.update("id", { text: "…" }) // modifie un élément qui a un id
bg.ui.badge("3")                 // petite pastille
await bg.ui.toast("Terminé")     // notify

await bg.composer.read()          // composer.read
await bg.composer.insert("texte") // composer.write
await bg.composer.replace("texte")// composer.write
await bg.thread.read()            // thread.read -> { agent, partial, messages: [{ role, text }] }
await bg.storage.get("clé")       // storage
await bg.storage.set("clé", valeur)
await bg.clipboard.write("texte") // clipboard.write
await bg.net.fetch("https://api.exemple.org/x", { method: "GET" }) // net -> { status, ok, type, text }
bg.on("open", () => {})           // le panneau devient visible
console.log("…")                  // visible dans la console du créateur

Interface elements

Kind Properties
title text
text text, tone (muted, good, bad)
button text, onClick, primary, disabled
input placeholder, value, onInput(valeur), onEnter(valeur)
textarea placeholder, value, rows, onInput(valeur)
toggle text, value, onChange(vrai/faux)
select options: [{ value, label }], value, onChange(valeur)
list items: [{ text, detail, value, onClick(value) }]
row children: [ … ] (on one line)
code text
progress value between 0 and 1
image src in data:image/…;base64,…
badge, divider —

Each element can have a id, used by bg.ui.update.

Complete example

// Compteur de mots (permission composer.read)
const t = bg.pick({ fr: "mots", en: "words" });
bg.ui.render([
  { type: "title", text: "Compteur" },
  { type: "text", id: "out", text: "…" },
]);
setInterval(async () => {
  const text = await bg.composer.read();
  const n = text.trim() ? text.trim().split(/\s+/).length : 0;
  bg.ui.update("out", { text: n + " " + t });
}, 1500);

Create, test, install

  1. Plugins > Create a plugin. Start from a template or an empty page.
  2. The name populates the identifier by itself. It is checked during entry.
  3. Check permissions, choose an icon, write the code.
  4. Test (Ctrl+Enter) launches the plugin in the preview, with its console. Storage there is temporary.
  5. Save and install, then Restart now: plugins load at startup.

Packages: import, update, export

Best practices

Troubleshooting