Web Widget

The web widget is a thin client over the REST API. Drop it into any page to give users a guided domain-connect experience.

Installation

Add the script tag, or install the npm package for bundler-based apps.

<script src="https://dns.global/widget.js"></script>

Initialization

Call DnsGlobal.init() with a backend-minted session token and your public key.

DnsGlobal.init({
  sessionToken: "sess_abc123...",
  publicKey: "pk_live_...",
  theme: { primaryColor: "#CF4520", borderRadius: 8 },
  onSuccess: (result) => console.log("Connected", result),
});

Theming

FieldTypeRequiredDescription
primaryColorstringnoAccent colour for buttons and highlights (hex).
borderRadiusnumbernoCorner radius in pixels.
fontFamilystringnoCSS font-family stack for widget text.
darkModebooleannoForce dark mode. Defaults to following the host page.

Callbacks

FieldTypeRequiredDescription
onPlanReady(plan) => voidnoFires when the change plan is computed, before the user confirms.
onSuccess(result) => voidnoFires after records are deployed and verified.
onError(error) => voidnoFires on any unrecoverable error.
onClose() => voidnoFires when the user dismisses the widget.

CSP configuration

If your site sends a Content-Security-Policy header, allow the widget origins:

script-src  https://dns.global;
connect-src https://api.dns.global;
frame-src   https://dns.global;

Note

The widget opens provider OAuth in a separate browser context, so you do not need to relax frame-src for provider domains.

Example: full integration

<!doctype html>
<html>
  <body>
    <button id="connect">Connect your domain</button>

    <script src="https://dns.global/widget.js"></script>
    <script>
      document.getElementById("connect").addEventListener("click", async () => {
        // Fetch a session token from YOUR backend (which calls /v1/sessions).
        const { sessionToken } = await fetch("/api/dns-session").then((r) => r.json());

        DnsGlobal.init({
          sessionToken,
          publicKey: "pk_live_...",
          onSuccess: (result) => {
            window.location.href = "/onboarding/domain-connected";
          },
        });
      });
    </script>
  </body>
</html>

Next steps

Was this page helpful?