Skip to content

Widget API

The KEPCA widget is a standard Web Component (<maptcha-widget>) that handles the entire challenge flow inside a Shadow DOM.

Installation

html
<script src="https://cdn.kepca.com/v1/maptcha.js" defer></script>

NPM / ESM

bash
pnpm add @maptcha/widget
js
import '@maptcha/widget';
// The <maptcha-widget> custom element is auto-registered on import.

HTML attributes

AttributeTypeDefaultDescription
data-sitekeystring(required)Your site key from the dashboard.
data-modestringadaptiveVerification mode: adaptive, invisible, checkbox, always-challenge.
data-langstringauto-detectLanguage code: en, tr, de, fr, es, ar, zh, ja, ru. Falls back to browser locale, then en.
data-themestringautoVisual theme: light, dark, auto. Auto follows prefers-color-scheme.
data-endpointstringProduction defaultOverride the KEPCA API URL. Useful for self-hosted or local development.

Example

html
<maptcha-widget
  data-sitekey="mpt_site_abc123"
  data-mode="adaptive"
  data-lang="tr"
  data-theme="dark"
  data-endpoint="https://api.kepca.com"
></maptcha-widget>

Events

The widget dispatches Custom Events that bubble and cross Shadow DOM boundaries (composed: true).

verify

Fired when verification succeeds. Contains the signed token.

js
widget.addEventListener('verify', (e) => {
  console.log(e.detail.token);
  // "eyJhbGciOiJIUzI1NiIsInYiOjF9.eyJzayI6Im1wdF9zaXRlXy..."
});

e.detail:

FieldTypeDescription
tokenstringHMAC-signed captcha token

error

Fired when verification fails (network error, invalid session, challenge expired, etc.).

js
widget.addEventListener('error', (e) => {
  console.error(e.detail.error);
  // "challenge_expired", "invalid_session", "network_error", etc.
});

e.detail:

FieldTypeDescription
errorstringError code or message

expire

Fired when a previously issued token expires (after 120 seconds).

js
widget.addEventListener('expire', () => {
  // Disable submit button, prompt re-verification
  submitBtn.disabled = true;
});

No detail payload.

CSS custom properties

The widget's Shadow DOM reads these CSS custom properties from the host element. Override them to match your site's design:

css
maptcha-widget {
  --mpt-bg: #ffffff;
  --mpt-text: #333333;
  --mpt-border: #d1d5db;
  --mpt-border-hover: #9ca3af;
  --mpt-check: #22c55e;
  --mpt-error: #ef4444;
  --mpt-brand: #6366f1;
  --mpt-shadow: rgba(0, 0, 0, 0.08);
}
PropertyDefault (light)Description
--mpt-bg#ffffffContainer background
--mpt-text#333333Label text color
--mpt-border#d1d5dbBorder color
--mpt-border-hover#9ca3afBorder on hover
--mpt-check#22c55eCheckmark / success color
--mpt-error#ef4444Error indicator color
--mpt-brand#6366f1Brand accent (spinner, logo)
--mpt-shadowrgba(0,0,0,.08)Box shadow color

Programmatic usage

For advanced use cases you can interact with the widget class directly:

MaptchaAPI

Low-level API client for the challenge service.

js
import { MaptchaAPI } from '@maptcha/widget';

const api = new MaptchaAPI('https://api.kepca.com');

// 1. Init session
const init = await api.init('mpt_site_abc123', {
  timestamp: Date.now(),
  time_on_page_ms: 5200,
  user_agent: navigator.userAgent,
});

// 2. Get challenge (if required)
if (init.requires_challenge) {
  const ch = await api.challenge('mpt_site_abc123', init.session_id, {
    timestamp: Date.now(),
  });

  // 3. Solve and submit
  const solution = await solvePow(ch.challenge.token, ch.challenge.difficulty);
  const result = await api.solve('mpt_site_abc123', init.session_id, solution);
  console.log(result.token);
}

Widget instance methods

MethodReturnsDescription
reset()voidReset the widget to idle state
getSitekey()stringGet the current site key
getLanguage()stringGet the resolved language code
getTheme()stringGet the resolved theme (light, dark, auto)
js
const widget = document.querySelector('maptcha-widget');
widget.reset(); // Return to unchecked state

KVKK/GDPR Uyumlu — Verileriniz yurt icinde kalir.