BugReporterWidget
A floating bug-report button (bottom-right corner) that opens a drawer for users to describe issues. Attaches recent console logs and the request timeline (credentials redacted). A screenshot (via html2canvas) is attached only when you opt in with captureScreenshot.
Import
import { BugReporterWidget } from '@mpratyush54/sdk-react';
Props
interface BugReporterWidgetProps {
config?: PlatformConfig; // defaults to the enclosing <PlatformProvider>'s config
captureScreenshot?: boolean; // default false
}
See PlatformProvider for the PlatformConfig shape.
Behaviour
- Renders a red 🐛 floating action button (fixed,
z-index: 99999, bottom-right). - Clicking toggles a dark-themed drawer:
- Textarea for the user's description.
- Hint describing what is attached; with
captureScreenshot, a checkbox the user can untick to skip the screenshot. - Cancel and Submit Report buttons.
- On submit:
- Only if
captureScreenshotis set and the box is ticked: captures the page viahtml2canvas(lazy-imported). Password, payment (autocomplete="cc-*"), one-time-code anddata-platform-maskfields are blanked in the cloned DOM first, and the widget itself is excluded. - POSTs to
POST /api/sdk/bug-report(Authorization: Bearer <token>) with:descriptioncategory: 'user-report'consoleLogs— captured from patchedconsole.log/warn/error(max 100 entries), with Authorization/Bearer values, SDK tokens, JWTs, cookies and password-like fields redactednetworkTimeline— method, redacted URL, status and duration from patchedwindow.fetch(max 100 entries; no headers or bodies)screenshotBase64— base64-encoded PNG, ornullwhen not opted inbrowserInfo—userAgent,url(redacted),viewportappState— empty object (extendable)
- Only if
- On success: shows a green "Bug report submitted" message for 2 s and closes.
- On failure: shows
alert('Failed to submit bug report.').
Full Example
import { PlatformProvider, BugReporterWidget } from '@mpratyush54/sdk-react';
export default function App() {
const platformConfig = {
apiBase: 'https://platform.example.com',
token: process.env.NEXT_PUBLIC_PLATFORM_TOKEN!,
projectId: 'my-app',
environment: 'production',
};
return (
<PlatformProvider config={platformConfig}>
<YourApp />
<BugReporterWidget config={platformConfig} />
</PlatformProvider>
);
}
Notes
- Console and
fetchpatching begins when the component mounts and is restored on unmount. - Screenshots are off by default. When enabled, one is taken only at submit time (not continuously). Mark any other sensitive element with
data-platform-maskto blank it. html2canvas(~40 KB gzipped) is lazy-loaded via dynamicimport()on first submit.