ai_explain_my_page

Element Intelligence (Capture + Meaning)

Demo

A zero-dependency drop-in script that lets you:

It ships as a single file and exposes three globals for flexibility:

Install

Include the single script:

<script src="/element-intelligence.js"></script>

This exposes global ElementInspector, ElementCapture, and ElementMeaning objects.

Quick start

<button id="start-capture">Start capture</button>
<button id="stop-capture">Stop capture</button>
<script>
  // Configure once at startup
  ElementInspector.configure({
    apiKey: '<YOUR_GEMINI_API_KEY>',
    applicationDescription: 'A SaaS dashboard for managing subscriptions and invoices'
  });

  // Start capture and auto-explain the clicked element
  document.getElementById('start-capture').addEventListener('click', function() {
    ElementInspector.captureAndExplain()
      .then(function(out) {
        console.log('Captured element:', out.element);
        if (out.result && out.result.ok) {
          console.log('[Explanation]', out.result.answerText);
        } else {
          console.warn('Explanation failed:', out.result && (out.result.message || out.result.code));
        }
      })
      .catch(function(err) {
        console.warn('Capture or explanation error:', err && err.message);
      });
  });

  // Stop capture programmatically
  document.getElementById('stop-capture').addEventListener('click', function() {
    ElementInspector.stop();
  });
</script>

Demo

Open the included demo with your API key provided via URL parameter:

/demo.html?api_key=YOUR_GEMINI_API_KEY

The demo logs both the captured element and the explanation to the browser console.

API

Where overrides may include: apiKey, model, applicationDescription, pageHtml, generationConfig, timeoutMs, extraContext, and the following callbacks:

ElementCapture (low-level)

ElementMeaning (low-level)

Error codes

Constants

Available at ElementMeaning.constants:

Notes