diff --git a/packages/browser-sdk/example/feedback-after-submit-demo/README.md b/packages/browser-sdk/example/feedback-after-submit-demo/README.md
new file mode 100644
index 000000000..99ba556b7
--- /dev/null
+++ b/packages/browser-sdk/example/feedback-after-submit-demo/README.md
@@ -0,0 +1,41 @@
+# `onAfterSubmit` timing demo
+
+Shows the real gap between a user submitting feedback and `onAfterSubmit`
+firing, and proves what happens to that callback — and to the feedback
+itself — if the tab goes away before the request completes.
+
+Builds the actual widget from this branch's `src/`, talking to a local mock
+API instead of `front.reflag.com`.
+
+## Run it
+
+From the repo root, with dependencies installed for `@reflag/browser-sdk`
+(`yarn install` once):
+
+```sh
+cd packages/browser-sdk
+node example/feedback-after-submit-demo/start.mjs
+```
+
+Open the printed URL (defaults to `http://localhost:5183`).
+
+## What to look at
+
+1. **Artificial latency** — widen the delay so the gap between submit and
+ `onAfterSubmit` is easy to see.
+2. **Live widget** — submit feedback for real. The banner stays red for as
+ long as the request is pending (`onAfterSubmit` has not run yet) and only
+ turns green once the callback actually fires.
+3. **Navigate away mid-submit** — fires the same request the widget's Send
+ button does, then navigates away before the response can arrive,
+ simulating a closed tab. The table's "server actually received it?" column
+ is ground truth from the mock API's own log, independent of whatever the
+ tab believes happened. On localhost this often still arrives — the request
+ is tiny and loopback latency is near zero, so sending finishes before the
+ navigation can interrupt it. On a real network that's not guaranteed:
+ without `keepalive` (which the SDK doesn't set for this request), a slower
+ connection can lose it outright; the `keepalive` checkbox bypasses the SDK
+ to show what setting it would buy you. What's guaranteed every time,
+ regardless of network speed or `keepalive`, is the other column: the
+ client never sees `onAfterSubmit` fire, because the page that would have
+ run it is gone.
diff --git a/packages/browser-sdk/example/feedback-after-submit-demo/gone.html b/packages/browser-sdk/example/feedback-after-submit-demo/gone.html
new file mode 100644
index 000000000..964adda47
--- /dev/null
+++ b/packages/browser-sdk/example/feedback-after-submit-demo/gone.html
@@ -0,0 +1,39 @@
+
+
+
+
+ Tab closed (simulated)
+
+
+
+
💥 This page just replaced the one that submitted feedback
+
+ Exactly like closing the tab or clicking a link right after hitting Send:
+ whatever JavaScript was waiting on the feedback response is gone now. No
+ onAfterSubmit can fire here — there is no callback left
+ to call it on.
+
+
Returning to the demo in a few seconds to check what the server saw…
Does onAfterSubmit survive the user closing the tab?
+
+ onAfterSubmit only fires once the feedback POST to Reflag
+ resolves, which means there is a real gap between the user clicking Send/a
+ score and the callback actually running. This page makes that gap visible,
+ and then proves what happens if the tab goes away before it closes.
+
+
+
+
1. Artificial network latency
+
+ Widens the gap between submit and onAfterSubmit so it's
+ easy to watch. The mock API server delays its response by this many
+ milliseconds.
+
+
+
+
+
+
+
+
+
+
2. Live widget
+
+ Open the real feedback widget (built from this branch's
+ src/, not a mock) and submit a score/comment. Watch the
+ banner and log below.
+
+
+
+
+
+
+
+
3. Prove it: navigate away mid-submit
+
+ This calls the exact same feedback() request the widget's
+ Send button triggers, then navigates away a moment later — simulating
+ the user closing the tab (or clicking a link) right after submitting,
+ before the response comes back. "Server actually received it?" is ground
+ truth from the mock API's own log, independent of anything the browser
+ tab believes happened.
+
+
+ On localhost, the request body is tiny and the round-trip to the mock
+ server is near-instant, so it often finishes sending before the
+ navigation can interrupt it — the row below may well show the server
+ received it either way. On a real network, with real latency, that's
+ not guaranteed: without `keepalive`, closing the tab can lose the
+ request outright. What is guaranteed, every time, is the
+ other column: the client never sees onAfterSubmit fire,
+ because the page that would have run it is gone.
+
+
+
+
+
+
+
+
+
+
+
+
Attempt
+
Mode
+
Sent
+
Client saw onAfterSubmit?
+
Server actually received it?
+
Verdict
+
+
+
+
+
+ Every row here is a deliberately interrupted attempt — that's the
+ point of this button. "Client saw onAfterSubmit?" reproduces the
+ widget's own await-then-notify sequence; "no" means the page was gone
+ before that sequence could finish.
+
+
+
+
+
+
diff --git a/packages/browser-sdk/example/feedback-after-submit-demo/main.ts b/packages/browser-sdk/example/feedback-after-submit-demo/main.ts
new file mode 100644
index 000000000..d4ca3e9de
--- /dev/null
+++ b/packages/browser-sdk/example/feedback-after-submit-demo/main.ts
@@ -0,0 +1,304 @@
+import { ReflagClient } from "../../src";
+
+const FLAG_KEY = "demo-flag";
+const ATTEMPTS_STORAGE_KEY = "reflag-demo-attempts";
+const API_BASE = `${location.origin}/api`;
+
+// --- Event log (section 2: the live widget) ------------------------------
+
+const logEl = document.querySelector("#log")!;
+const bannerEl = document.querySelector("#risk-banner")!;
+
+let pendingSince: number | null = null;
+let requestInFlight = false;
+let bannerTimer: number | undefined;
+
+function logLine(text: string, kind: "ok" | "pending" | "err" = "pending") {
+ const line = document.createElement("div");
+ line.className = kind;
+ const t = new Date().toLocaleTimeString([], { hour12: false });
+ line.textContent = `[${t}] ${text}`;
+ logEl.appendChild(line);
+ logEl.scrollTop = logEl.scrollHeight;
+}
+
+function openRiskWindow() {
+ pendingSince = performance.now();
+ requestInFlight = true;
+ bannerEl.className = "pending";
+ tickBanner();
+ if (bannerTimer === undefined)
+ bannerTimer = window.setInterval(tickBanner, 50);
+}
+
+function onFeedbackRequestSettled() {
+ // The POST resolved, so the data is safely on the server. onAfterSubmit is
+ // still deferred until Send or a dialog close, by design (see
+ // withFeedbackSubmissionCallback) — so an abrupt tab close here loses the
+ // callback even though it would NOT lose the feedback itself.
+ requestInFlight = false;
+ tickBanner();
+}
+
+function tickBanner() {
+ if (pendingSince === null) return;
+ const elapsed = Math.round(performance.now() - pendingSince);
+ bannerEl.textContent = requestInFlight
+ ? `⚠ request pending for ${elapsed}ms — closing the tab right now would lose this feedback entirely. onAfterSubmit has NOT fired yet.`
+ : `⚠ response received ${elapsed}ms ago, feedback is saved server-side — but onAfterSubmit is still waiting on Send or the dialog closing. Closing the tab right now would lose the callback (not the data).`;
+}
+
+function closeRiskWindow(fired: boolean) {
+ if (bannerTimer !== undefined) {
+ clearInterval(bannerTimer);
+ bannerTimer = undefined;
+ }
+ if (pendingSince === null) return;
+ const elapsed = Math.round(performance.now() - pendingSince);
+ pendingSince = null;
+ requestInFlight = false;
+ if (fired) {
+ bannerEl.className = "resolved";
+ bannerEl.textContent = `✓ onAfterSubmit fired after ${elapsed}ms. Safe to close the tab now.`;
+ }
+}
+
+// Intercept fetch purely to see exactly when the request to /api/feedback
+// leaves the browser and when its response comes back — this is the gap
+// onAfterSubmit waits out, observed from the outside without touching the
+// widget's internals.
+const originalFetch = window.fetch.bind(window);
+window.fetch = (input, init) => {
+ const url = String(input instanceof Request ? input.url : input);
+ const method =
+ init?.method ?? (input instanceof Request ? input.method : "GET");
+ const isFeedbackSubmit = url.endsWith("/api/feedback") && method === "POST";
+
+ if (isFeedbackSubmit) {
+ logLine("→ POST /feedback sent", "pending");
+ openRiskWindow();
+ }
+
+ const result = originalFetch(input, init);
+
+ if (isFeedbackSubmit) {
+ result
+ .then(() => {
+ logLine("← response received from server", "ok");
+ onFeedbackRequestSettled();
+ })
+ .catch(() => {
+ logLine("✕ request failed/aborted", "err");
+ onFeedbackRequestSettled();
+ });
+ }
+
+ return result;
+};
+
+// --- Reflag client ---------------------------------------------------------
+
+const reflag = new ReflagClient({
+ publishableKey: "demo-publishable-key",
+ user: { id: "demo-user" },
+ company: { id: "demo-company" },
+ apiBaseUrl: API_BASE,
+ enableTracking: false,
+ feedback: { enableAutoFeedback: false },
+});
+
+reflag.initialize();
+
+document.querySelector("#open-widget")!.addEventListener("click", (event) => {
+ reflag.requestFeedback({
+ flagKey: FLAG_KEY,
+ title: "How do you like this demo?",
+ position: { type: "POPOVER", anchor: event.currentTarget as HTMLElement },
+ onAfterSubmit: (data) => {
+ logLine(
+ `✓ onAfterSubmit called (score=${data.score}, comment=${JSON.stringify(data.comment)}, feedbackId=${data.feedbackId})`,
+ "ok",
+ );
+ closeRiskWindow(true);
+ },
+ });
+});
+
+// --- Artificial latency control --------------------------------------------
+
+const delayInput = document.querySelector("#delay-input")!;
+const delayStatus = document.querySelector("#delay-status")!;
+
+async function refreshDelay() {
+ const res = await fetch(`${API_BASE}/log`);
+ const { delayMs } = await res.json();
+ delayInput.value = String(delayMs);
+ delayStatus.textContent = `current: ${delayMs}ms`;
+}
+
+document.querySelector("#apply-delay")!.addEventListener("click", async () => {
+ const delayMs = Number(delayInput.value);
+ const res = await fetch(`${API_BASE}/config`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ delayMs }),
+ });
+ const body = await res.json();
+ delayStatus.textContent = `current: ${body.delayMs}ms`;
+});
+
+refreshDelay();
+
+// --- Danger zone: navigate away mid-submit ----------------------------------
+
+type Attempt = {
+ id: string;
+ mode: "sdk (no keepalive)" | "raw fetch (keepalive)";
+ sentAt: number;
+ clientConfirmedAt: number | null;
+ serverConfirmedAt: number | null;
+};
+
+function loadAttempts(): Attempt[] {
+ try {
+ return JSON.parse(localStorage.getItem(ATTEMPTS_STORAGE_KEY) ?? "[]");
+ } catch {
+ return [];
+ }
+}
+
+function saveAttempts(attempts: Attempt[]) {
+ localStorage.setItem(ATTEMPTS_STORAGE_KEY, JSON.stringify(attempts));
+}
+
+function renderAttempts(
+ serverReceived: { attemptId: string | null; receivedAt: number }[],
+) {
+ const attempts = loadAttempts();
+ const tbody = document.querySelector("#attempts tbody")!;
+ tbody.innerHTML = "";
+
+ for (const attempt of attempts) {
+ const serverHit = serverReceived.find((r) => r.attemptId === attempt.id);
+ if (serverHit && !attempt.serverConfirmedAt) {
+ attempt.serverConfirmedAt = serverHit.receivedAt;
+ }
+
+ const clientOk = attempt.clientConfirmedAt !== null;
+ const serverOk = attempt.serverConfirmedAt !== null;
+
+ let verdict: string;
+ let verdictClass: string;
+ if (clientOk && serverOk) {
+ verdict = "delivered, callback fired";
+ verdictClass = "verdict-ok";
+ } else if (!clientOk && serverOk) {
+ verdict =
+ "server got it, but onAfterSubmit never ran — don't rely on it for anything that must survive navigation";
+ verdictClass = "verdict-partial";
+ } else {
+ verdict =
+ "feedback lost entirely — the request itself was killed by the navigation";
+ verdictClass = "verdict-lost";
+ }
+
+ const row = document.createElement("tr");
+ row.innerHTML = `
+