|
| 1 | +--- |
| 2 | +import DocsLayout from '../../components/DocsLayout.astro'; |
| 3 | +import { Code } from 'astro:components'; |
| 4 | +--- |
| 5 | + |
| 6 | +<DocsLayout title="Browser" section="browser"> |
| 7 | + <h1>Browser</h1> |
| 8 | + <p class="lead">Drop a script tag into any page — or import as an ES module. Same API as the Node.js client. No build step required.</p> |
| 9 | + |
| 10 | + <h2>Script tag (CDN)</h2> |
| 11 | + <Code code={`<script src="https://cdn.jsdelivr.net/npm/@fanar-app/fanar-browser/dist/fanar.js"></script> |
| 12 | +<script> |
| 13 | + fanar('hello from the browser') |
| 14 | + fanar({ user, cart }).label('checkout') |
| 15 | + fanar(new Error('something went wrong')) |
| 16 | + fanar.time('render').stop() |
| 17 | +</script>`} lang="html" theme="github-dark" /> |
| 18 | + |
| 19 | + <h2>ES module</h2> |
| 20 | + <Code code={`<script type="module"> |
| 21 | + import fanar from 'https://cdn.jsdelivr.net/npm/@fanar-app/fanar-browser/dist/index.js' |
| 22 | +
|
| 23 | + fanar('hello') |
| 24 | + fanar({ user, cart }).label('checkout') |
| 25 | + fanar.time('render').stop() |
| 26 | +</script>`} lang="html" theme="github-dark" /> |
| 27 | + |
| 28 | + <h2>npm</h2> |
| 29 | + <Code code={`npm install @fanar-app/fanar-browser`} lang="bash" theme="github-dark" /> |
| 30 | + <Code code={`import fanar from '@fanar-app/fanar-browser' |
| 31 | +
|
| 32 | +fanar('hello') |
| 33 | +fanar({ user, session }).label('auth') |
| 34 | +fanar(new Error('oops')) |
| 35 | +fanar.time('paint').stop()`} lang="javascript" theme="github-dark" /> |
| 36 | + |
| 37 | + <h2>API</h2> |
| 38 | + <table> |
| 39 | + <tr><th>Call</th><th>Description</th></tr> |
| 40 | + <tr><td>fanar(value)</td><td>Auto-dispatch — string/number → log, object → dump, Error → exception</td></tr> |
| 41 | + <tr><td>.label(str)</td><td>Chain a label onto any call</td></tr> |
| 42 | + <tr><td>.color(str)</td><td>Chain a color tag onto any call</td></tr> |
| 43 | + <tr><td>fanar.time(label)</td><td>Start a named timer — call <code>.stop()</code> to send elapsed ms</td></tr> |
| 44 | + <tr><td>fanar.query(sql, opts)</td><td>Send a SQL query with optional bindings and duration</td></tr> |
| 45 | + <tr><td>fanar.clear()</td><td>Clear all payloads in the Fanar app</td></tr> |
| 46 | + <tr><td>fanar.configure(opts)</td><td>Set <code>host</code> and <code>port</code> (default: <code>localhost:23517</code>)</td></tr> |
| 47 | + </table> |
| 48 | + |
| 49 | + <h2>Configuration</h2> |
| 50 | + <Code code={`fanar.configure({ host: '192.168.1.5', port: 23517 })`} lang="javascript" theme="github-dark" /> |
| 51 | + |
| 52 | + <h2>CORS</h2> |
| 53 | + <p>The Fanar app must have CORS enabled to accept requests from browser pages. This is on by default for <code>localhost</code> origins. For remote hosts, set <code>FANAR_CORS_ORIGIN</code> in the Fanar app config.</p> |
| 54 | +</DocsLayout> |
0 commit comments