Build your first app

Build a reading marker for example.com with a userscript and a settings page.

The workspace

Complete setup first. Keep Chrome open with Sloppy enabled. The companion watches your workspace; there is no separate development server to start for this example.

Create the following files under ~/.sloppy/apps/reading-marker. The app’s folder name and manifest ID must match.

Workspace layout
~/.sloppy/
├── apps/
│   └── reading-marker/
│       ├── manifest.json
│       ├── userscripts/
│       │   └── marker.ts
│       └── ui/
│           ├── App.tsx
│           └── globals.css
├── shared/            # Managed components and theme
├── docs/              # Local SDK documentation
└── AGENTS.md          # Instructions for your coding agent

1. Manifest

This manifest limits the userscript to https://example.com/. Start with one site instead of a wildcard covering the whole web.

apps/reading-marker/manifest.json
{
  "id": "reading-marker",
  "name": "Reading Marker",
  "version": "0.1.0",
  "description": "A small reminder to read with intention.",
  "userscripts": [
    {
      "file": "userscripts/marker.ts",
      "matches": ["https://example.com/*"]
    }
  ]
}

2. Userscript

The default userscript context can read and change the page’s DOM and use the sloppy.* SDK. This example checks a saved setting, avoids adding duplicate markers, and leaves the page’s content alone.

apps/reading-marker/userscripts/marker.ts
async function addMarker() {
  const enabled = await sloppy.storage.get<boolean>('showMarker');
  if (enabled === false || document.getElementById('sloppy-reading-marker')) return;

  const marker = document.createElement('aside');
  marker.id = 'sloppy-reading-marker';
  marker.textContent = 'One page at a time.';
  Object.assign(marker.style, {
    position: 'fixed', bottom: '20px', right: '20px',
    maxWidth: 'calc(100vw - 40px)', padding: '12px 16px',
    background: '#f5f2e9', color: '#580d14',
    border: '1px solid #cecac0', borderRadius: '8px',
    font: '600 14px/1.4 system-ui, sans-serif',
    zIndex: '2147483647', pointerEvents: 'none'
  });
  document.body.append(marker);
}

void addMarker().catch(error => {
  console.error('Reading Marker could not start', error);
});

A storage value of undefined uses the default “on” behavior. The setting takes effect the next time the matching page loads.

3. App page

Every app needs a UI entry. Use the managed AppPage component so its name, settings, and preview fit the dashboard. The setting below is stored for this app only.

apps/reading-marker/ui/App.tsx
import { useEffect, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { AppPage, SettingsSection } from '@shared/components';
import './globals.css';

function App() {
  const [enabled, setEnabled] = useState(true);
  const [ready, setReady] = useState(false);
  const [saving, setSaving] = useState(false);
  const [error, setError] = useState('');

  useEffect(() => {
    let active = true;
    sloppy.storage.get<boolean>('showMarker').then(value => {
      if (active) { setEnabled(value !== false); setReady(true); }
    }).catch(() => {
      if (active) setError('Could not load the setting. Reopen this app to retry.');
    });
    return () => { active = false; };
  }, []);

  async function save(next: boolean) {
    setSaving(true);
    setError('');
    try {
      await sloppy.storage.set('showMarker', next);
      setEnabled(next);
    } catch {
      setError('Could not save. Please try again.');
    } finally {
      setSaving(false);
    }
  }

  return <AppPage appId="reading-marker" name="Reading Marker"
    description="A small reminder on example.com."
    preview={<div style={{ background: '#f5f2e9', color: '#580d14',
      border: '1px solid #cecac0', borderRadius: 8, padding: '12px 16px',
      font: '600 14px/1.4 system-ui, sans-serif', maxWidth: '100%' }}>
      One page at a time.
    </div>}>
    <SettingsSection title="The marker">
      <label style={{ display: 'flex', gap: 12, alignItems: 'center', minHeight: 44 }}>
        <input type="checkbox" checked={enabled} disabled={!ready || saving}
          onChange={event => void save(event.target.checked)} />
        Show the reading marker
      </label>
      <p>Reload example.com after changing this setting.</p>
      {error && <p role="alert">{error}</p>}
    </SettingsSection>
  </AppPage>;
}

createRoot(document.getElementById('root')!).render(<App />);
apps/reading-marker/ui/globals.css
@import "tailwindcss";
@import "@shared/theme/tailwind-theme.css";

4. Try it

  1. Wait a few seconds for the companion to pick up the new app. Open Reading Marker in the Sloppy dashboard.
  2. Open example.com in a fresh tab. Look for the reading marker in the lower-right corner.
  3. Turn off the setting in the app’s page. Reload your test tab; the marker should disappear.
  4. Turn it back on and reload again. Check that one marker appears and that the page remains readable.
Terminal · inspect runtime errors
cd ~/.sloppy
bun run --bun tsc --noEmit
sloppy browser logs --level error -n 50

The companion bundles TypeScript without type-checking it. Run the type checker separately, inspect the errors for your app, and exercise the behavior in a real tab. A clean log alone does not prove the app works.

CheckThe marker appears only on its matching website, respects the saved setting after reload, and does not produce app errors.

Build further

Change the message, move the marker, or choose a specific website you use. Add settings for choices you want to change later. If you add dependencies, declare them in the app’s own package.json.

Server functions belong in server/<name>.ts, default-export a function, and are called with sloppy.rpc('<name>', payload). Keep private API keys server-side. Read the complete ~/.sloppy/docs/app-developer-guide.md and sdk-reference.md supplied with your installed companion before adding advanced integrations.

Cloud features are covered in permissions and data.