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
- Each plugin runs in its own Worker, isolated from Grok and Better: no page, no DOM, no local bridge.
- Before your code, Better removes
fetch,XMLHttpRequest,WebSocket,indexedDB,caches,importScriptsand other network and storage access. - A plugin only does what its
plugin.jsondeclares. Each request goes through Better, which checks the permission. - Never accessible: API keys, tokens, passwords, your files, the Grok page, other plugins.
- A plugin that no longer responds (infinite loop) or that accumulates errors is stopped and deactivated. If a startup fails, Better restarts in safe mode, without any plugins.
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
- Plugins > Create a plugin. Start from a template or an empty page.
- The name populates the identifier by itself. It is checked during entry.
- Check permissions, choose an icon, write the code.
- Test (Ctrl+Enter) launches the plugin in the preview, with its console. Storage there is temporary.
- Save and install, then Restart now: plugins load at startup.
Packages: import, update, export
- Import: drag a plugin folder, a
.zipor a.bgbpluginonto the window (Plugins tab open), or use Import folder / Import archive. - A package can contain one plugin (root files) or several (one folder per plugin).
- Better validates each manifest, shows the permissions and version (new, updated, older), then asks for confirmation.
- Update: Upload a higher version. The old one is kept in
plugins/.versions. - Export creates a
.zipready to share. Remove moves the folder toplugins/.corbeille: nothing is deleted. - Limits: 5 MB and 200 files per package; extensions
.json .js .md .txt .css .svg .png .jpg .webp.
Best practices
- Only one task per plugin, well named.
- Ask for the minimum amount of permissions; explain them in the description.
- Translate your texts with
bg.pick. - No timer faster than necessary (one second is almost always enough).
- Keep useful data only, and never secrets in the code.
- Increase
versionwith each publication.
Troubleshooting
- “invalid identifier”: Use only
a-z,0-9and hyphens, for examplemon-outil. - “permission...undeclared”: add it in
permissions, then reinstall. - “undeclared host”: add the domain in
hosts(with permissionnet). - Plugin stopped for safety: it has looped or accumulated errors. Fix it, then re-enable it.
- Safe Mode: Plugins > Exit Safe Mode, then restart.