### Breadcrumbs Setup Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Demonstrates how to set up and configure breadcrumbs for tracking user interactions and application state. ```javascript import { BrowserBreadcrumbStore } from "@hawk.js/browser"; BrowserBreadcrumbStore.init({ maxBreadcrumbs: 50, beforeBreadcrumb: (breadcrumb) => { // Modify or filter breadcrumbs return breadcrumb; } }); ``` -------------------------------- ### Start Development Server with Yarn Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/sveltekit/playground/README.md Run this command to start the SvelteKit development server. This command is typically used after installing dependencies. ```shell yarn dev ``` -------------------------------- ### Minimal Hawk Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Basic setup for Hawk JavaScript to start capturing errors. Requires minimal configuration. ```javascript import { Hawk } from "@hawk.js/hawk"; Hawk.init({ public_key: "YOUR_PUBLIC_KEY", // ... other options }); ``` -------------------------------- ### Install @hawk.so/sveltekit Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Install the SvelteKit SDK using npm or yarn. ```bash npm install @hawk.so/sveltekit # or yarn add @hawk.so/sveltekit ``` -------------------------------- ### Install with npm Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/core/README.md Install the core package using npm. ```shell npm install @hawk.so/core --save ``` -------------------------------- ### Install with yarn Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/core/README.md Install the core package using yarn. ```shell yarn add @hawk.so/core ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/sveltekit/playground/README.md Use this command to install project dependencies. Ensure Yarn is installed and configured for your project. ```shell yarn install ``` -------------------------------- ### Full Hawk Configuration Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt An example demonstrating a comprehensive configuration for Hawk JavaScript, including various options for error tracking and reporting. ```javascript import { Hawk } from "@hawk.js/hawk"; Hawk.init({ public_key: "YOUR_PUBLIC_KEY", base_url: "https://api.hawk.js", // ... more options }); ``` -------------------------------- ### Install Hawk SvelteKit Package Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/sveltekit/README.md Install the Hawk SDK for SvelteKit using npm. ```shell npm install @hawk.so/sveltekit --save ``` -------------------------------- ### Install Hawk JavaScript SDK Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Install the browser or SvelteKit specific package using npm or yarn. ```bash npm install @hawk.so/browser # or yarn add @hawk.so/browser ``` ```bash npm install @hawk.so/sveltekit ``` -------------------------------- ### Install Hawk.JavaScript Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/README.md Install the browser SDK using npm. This is the first step to integrate Hawk error tracking into your web application. ```bash npm install @hawk.so/browser ``` -------------------------------- ### Hawk JavaScript Installation Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Instructions for installing the Hawk JavaScript library. This is a prerequisite for using any of its features. ```bash npm install @hawk.js/hawk ``` -------------------------------- ### Vue.js Integration Example Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/example/index.html Demonstrates how to integrate Hawk JavaScript with Vue.js applications. This example shows setting up a Vue instance and triggering an error from a method. ```javascript new Vue({ el: '#vue-app-1', data: { label: 'Error in Vue $root', }, methods: { buttonClicked() { foo(); }, }, }); ``` -------------------------------- ### Example BeforeSendHook Implementation Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/01-core-catcher.md An example of implementing the BeforeSendHook to drop specific events (e.g., 'script error') or modify event context before sending. ```javascript const settings = { beforeSend(event) { if (event.title.includes('script error')) { return false; // Drop CORS errors } event.context = { ...event.context, filtered: true }; return event; // Send modified event } }; ``` -------------------------------- ### Minimal Hawk SDK Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Initialize the Hawk SDK with your integration token. Errors are automatically caught, or you can send them manually. ```typescript import Catcher from '@hawk.so/browser'; const hawk = new Catcher('YOUR_INTEGRATION_TOKEN'); // Errors are automatically caught // or send manually: hawk.send(new Error('Something went wrong')); ``` -------------------------------- ### Install Hawk via NPM Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/README.md Install the Hawk browser package using NPM. This is the recommended way to add Hawk to your project. ```shell npm install @hawk.so/browser --save ``` -------------------------------- ### Browser Logger Console Output Examples Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/11-logging.md Examples of console output for different log levels (Info, Warning, Error) using the browser logger. ```text [Hawk vX.Y.Z] Connection lost. Connection will be restored when new errors occurred ``` ```text [Hawk vX.Y.Z] Integration Token is missed. You can get it on https://hawk.so at Project Settings. [Hawk vX.Y.Z] validateUser: User must be an object [Hawk vX.Y.Z] Invalid beforeSend value. It should return event or false. Event is sent without changes. ``` ```text [Hawk vX.Y.Z] Unable to send error. Seems like it is Hawk internal bug. [Hawk vX.Y.Z] WebSocket sending error [Hawk vX.Y.Z] Can not parse stack ``` -------------------------------- ### Install Hawk via Yarn Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/README.md Install the Hawk browser package using Yarn. This provides an alternative to NPM for package management. ```shell yarn add @hawk.so/browser ``` -------------------------------- ### Minimal Setup for Hawk JavaScript Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/09-configuration.md Initialize Hawk with only a token, relying on all other configurations to use their default values. ```typescript const hawk = new Catcher('YOUR_INTEGRATION_TOKEN'); // Uses all defaults ``` -------------------------------- ### SvelteKit Integration Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Instructions and examples for integrating Hawk JavaScript with SvelteKit applications. ```APIDOC ## SvelteKit Integration ### Description Guides and examples for integrating Hawk JavaScript with SvelteKit. ### Installation Instructions Steps to install the Hawk SDK in a SvelteKit project. ### Root Layout Initialization How to initialize the SDK in the root layout. ### Client-side Error Handling Setting up error handling on the client side. ### User Tracking Integrating user tracking within SvelteKit. ### Context and Release Setup Configuring context and release information. ### Server-side Handling Handling errors and data on the server side. ### Hook Integration Integrating with SvelteKit hooks. ### Error Page Integration Integrating with SvelteKit's error pages. ### API Route Integration Handling errors within API routes. ### Form Action Integration Integrating with SvelteKit form actions. ### Environment-specific Config Configuring the SDK based on the environment. ### Shared Instance Pattern Using a shared SDK instance across the application. ### Performance Monitoring Setting up performance monitoring in SvelteKit. ### Testing Setup Configuring the SDK for testing in SvelteKit. ### Full Example Application A complete example application demonstrating SvelteKit integration. ``` -------------------------------- ### Console Tracking Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Enabling the tracking of console messages (like errors and warnings) as events. ```javascript import { BrowserCatcher } from "@hawk.js/browser"; const catcher = new BrowserCatcher({ // ... options captureConsole: true }); ``` -------------------------------- ### Sanitizer Registration Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Shows how to register a custom handler with the Sanitizer class to handle specific data types. ```javascript import { Sanitizer } from "@hawk.js/core"; const customHandler = { type: "MyCustomType", sanitize: (data) => "" }; Sanitizer.registerHandler(customHandler); ``` -------------------------------- ### Global Error Handling Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Configuring global error handlers for uncaught exceptions and unhandled rejections in the browser. ```javascript window.onerror = (message, source, lineno, colno, error) => { // Handle global errors }; window.onunhandledrejection = (event) => { // Handle unhandled promise rejections }; ``` -------------------------------- ### Minimal Hawk Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/README.md Initialize the Catcher with your integration token for basic error tracking. Errors will be automatically caught and sent. ```typescript import Catcher from '@hawk.so/browser'; const hawk = new Catcher('YOUR_INTEGRATION_TOKEN'); // Errors automatically caught, or send manually: hawk.send(new Error('Something went wrong')); ``` -------------------------------- ### Hawk User Management Usage Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/03-user-management.md Demonstrates the typical workflow of initializing Hawk, setting an anonymous user, logging in a specific user, and handling logout. ```typescript import Catcher from '@hawk.so/browser'; const hawk = new Catcher('YOUR_INTEGRATION_TOKEN'); // First visit: auto-generated anonymous ID hawk.setUser({ id: 'auto-generated-uuid' }); // After user login hawk.setUser({ id: 'user-123', email: 'user@example.com', name: 'John Doe' }); // Events now include identified user // On logout hawk.clearUser(); // Falls back to persisted anonymous ID // Subsequent errors attributed to anonymous user ``` -------------------------------- ### Custom Transport Implementation Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Example of creating and using a custom transport mechanism for sending events. ```javascript import { Hawk } from "@hawk.js/hawk"; class CustomTransport { send(payload) { console.log("Sending payload:", payload); // Implement custom sending logic } } Hawk.init({ public_key: "YOUR_PUBLIC_KEY", transport: new CustomTransport() }); ``` -------------------------------- ### Minimal Hawk SDK Initialization Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/09-configuration.md Use this minimal setup for basic error handling, breadcrumbs, console tracking, and WebSocket transport. Ensure you replace 'YOUR_INTEGRATION_TOKEN' with your actual token. ```typescript import Catcher from '@hawk.so/browser'; const hawk = new Catcher('YOUR_INTEGRATION_TOKEN'); ``` -------------------------------- ### Validation Utilities Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Demonstrates the usage of validation utility functions provided by Hawk. ```javascript import { isValidEventPayload } from "@hawk.js/core"; const payload = { message: "Test" }; if (isValidEventPayload(payload)) { console.log("Payload is valid."); } ``` -------------------------------- ### BacktraceFrame Interface Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/05-stack-parsing.md An example of the BacktraceFrame interface structure, which includes file, line, column, function name, and optional source code context. ```json { file: "https://example.com/js/app.js", line: 45, column: 12, function: "processData", sourceCode: [ { line: 40, content: "function processData(data) {" }, { line: 41, content: " if (!data.id) {" }, { line: 42, content: " const value = data.value;" }, { line: 43, content: " return doSomething(value);" }, { line: 44, content: " }" }, { line: 45, content: " const result = JSON.parse(data); // ERROR" }, { line: 46, content: " return result;" } ] } ``` -------------------------------- ### Manual Stack Parsing Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/05-stack-parsing.md Instantiate StackParser and use it to parse an error object. This example demonstrates iterating through parsed frames and displaying source code lines if available. Requires an async context. ```typescript import { StackParser } from '@hawk.so/core'; const parser = new StackParser(); try { throw new Error('Test error'); } catch (error) { const frames = await parser.parse(error); frames.forEach(frame => { console.log(`Frame: ${frame.function || 'anonymous'}`); console.log(` Location: ${frame.file}:${frame.line}:${frame.column}`); if (frame.sourceCode) { frame.sourceCode.forEach(line => { const marker = line.line === frame.line ? '>>>' : ' '; console.log(`${marker} ${line.line}: ${line.content}`); }); } }); } ``` -------------------------------- ### Full SvelteKit Application Setup with Hawk Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Integrate Hawk into the root layout of a SvelteKit application. This includes configuring token, release, context, breadcrumbs, and issue reporting. ```typescript ``` -------------------------------- ### Browser Catcher Initialization Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Example of initializing the Browser Catcher class for client-side error monitoring. ```javascript import { BrowserCatcher } from "@hawk.js/browser"; const catcher = new BrowserCatcher({ public_key: "YOUR_PUBLIC_KEY", // ... browser-specific options }); catcher.init(); ``` -------------------------------- ### BrowserBreadcrumbStore.init() Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Initializes the breadcrumbs functionality with optional configuration settings and starts automatic event capturing. It can throw an error if called when already initialized. ```APIDOC ## init(options) ### Description Initialize breadcrumbs with options and start auto-capture. This method is typically called automatically by the Catcher constructor, so manual invocation is usually unnecessary. ### Method Signature ```typescript public init(options: BreadcrumbsOptions = {}): void ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (BreadcrumbsOptions) - Optional - Configuration options for breadcrumbs, such as `maxBreadcrumbs`, `trackFetch`, `trackNavigation`, `trackClicks`, and `beforeBreadcrumb`. ### Throws - Error: If the breadcrumbs have already been initialized. Call `destroy()` first. ### Example ```typescript const store = BrowserBreadcrumbStore.getInstance(); store.init({ maxBreadcrumbs: 50, trackFetch: true, trackNavigation: true, trackClicks: true, beforeBreadcrumb(breadcrumb) { return breadcrumb; // or false to discard } }); ``` ``` -------------------------------- ### Class Sanitization Examples Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/06-sanitizer.md Demonstrates how class prototypes and instances are represented during sanitization. Prototypes are shown as '' and instances as ''. ```text Input: class Editor { } Output: '' Input: new Editor() Output: '' ``` -------------------------------- ### Mock Hawk in Vitest Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Mock the Hawk SDK functions in your Vitest setup file to prevent actual calls during testing. This ensures tests run in isolation. ```typescript // src/vitest.setup.ts import { vi } from 'vitest'; // Mock Hawk in tests global.HawkMock = { send: vi.fn(), setUser: vi.fn(), clearUser: vi.fn() }; ``` -------------------------------- ### Custom Storage Implementation Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/03-user-management.md Example of a custom HawkStorage implementation using sessionStorage. This can be used to initialize HawkUserManager with alternative storage mechanisms. ```typescript class CustomStorage implements HawkStorage { getItem(key: string): string | null { return sessionStorage.getItem(key); } setItem(key: string, value: string): void { sessionStorage.setItem(key, value); } } const userManager = new HawkUserManager( new CustomStorage(), new BrowserRandomGenerator() ); ``` -------------------------------- ### Example AffectedUser Object Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/03-user-management.md Demonstrates creating an AffectedUser object with required and optional fields, including custom properties. ```typescript hawk.setUser({ id: 'user-12345', email: 'user@example.com', name: 'Jane Smith', plan: 'premium', accountAge: 365, preferences: { language: 'en' } }); ``` -------------------------------- ### Configure Vitest for SvelteKit Tests Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Set up Vitest configuration for SvelteKit projects. This includes enabling global test functions and specifying a setup file for environment configuration. ```typescript // vite.config.ts import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, environment: 'jsdom', setupFiles: './src/vitest.setup.ts' } }); ``` -------------------------------- ### Initialize Catcher with Integration Token Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/02-browser-catcher.md Use a string for minimal setup by passing your integration token directly to the Catcher constructor. ```typescript const hawk = new Catcher('YOUR_INTEGRATION_TOKEN'); ``` -------------------------------- ### Complete Hawk Browser Catcher Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/02-browser-catcher.md Initialize the Hawk browser catcher with comprehensive configuration including integration token, release version, debug mode, user details, environment context, breadcrumb customization, and custom event filtering. ```typescript import Catcher from '@hawk.so/browser'; const hawk = new Catcher({ token: 'YOUR_INTEGRATION_TOKEN', release: '1.2.3', debug: process.env.NODE_ENV === 'development', user: { id: 'user-123', email: 'user@example.com', name: 'John Doe' }, context: { environment: process.env.NODE_ENV, region: 'us-west-1' }, breadcrumbs: { maxBreadcrumbs: 25, beforeBreadcrumb(breadcrumb) { // Remove sensitive data if (breadcrumb.data?.password) { delete breadcrumb.data.password; } return breadcrumb; } }, beforeSend(event) { // Filter out CORS errors if (event.title === 'Script error.') { return false; } return event; }, issues: { errors: true, longTasks: { thresholdMs: 100 }, webVitals: true } }); // Manual error sending hawk.send(new Error('Custom error')); // Update user on login hawk.setUser({ id: 'new-user-123' }); // Clear user on logout hawk.clearUser(); ``` -------------------------------- ### Automatic Browser Logger Setup Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/11-logging.md Demonstrates how to automatically set the browser logger when initializing the Catcher if a logger hasn't already been set. ```typescript import { isLoggerSet, setLogger } from '@hawk.so/core'; import { createBrowserLogger } from '@hawk.so/browser/utils/logger'; // In catcher.ts if (!isLoggerSet()) { setLogger(createBrowserLogger(VERSION)); } ``` -------------------------------- ### Hawk SDK Integration for Stack Parsing Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/05-stack-parsing.md Shows how the StackParser is typically used automatically within the Hawk SDK's `send` method, and provides a manual instantiation example for direct use when needed. ```typescript // Automatic (in Catcher) hawk.send(error); // Uses StackParser internally // Manual (if needed) const parser = new StackParser(); const frames = await parser.parse(error); ``` -------------------------------- ### Fetch Request Breadcrumb Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Automatically captured when trackFetch is enabled. Includes details about the request and response. ```typescript { type: 'request', category: 'fetch', message: '200 GET https://api.example.com/users', level: 'info' | 'error', data: { url: 'https://api.example.com/users', method: 'GET', statusCode: 200, durationMs: 145 } } ``` -------------------------------- ### Vue.js Component Example Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/example/index.html This snippet shows a Vue.js component definition including data, props, computed properties, template, and methods. It also demonstrates initializing Vue with a specific element. ```javascript class Editor {} const tag = document.createElement('div'); tag.classList.add('my-class', 'my-class--second'); tag.setAttribute('title', 'My title'); tag.dataset.index = 123; tag.innerHTML = document.body.innerHTML; Vue.component('test-component', { data() { return { number: 1, bool: false, arr: [1, 2, 3, [new Editor(), tag.cloneNode()], { foo: 'bar' }], el: tag, instance: new Editor(), classProto: Editor, longText: "Upvoting this, given it's simplicity. In my use case I need to check all the attributes in an object for dodgy values-NaNs, nulls, undefined (they were points on a graph and these values prevented the graph from drawing). To get the value instead of the name, in the loop you would just do obj[someVariable]. Perhaps the reason it was downvoted so much is because it is not recursive. So this would not be an adequate solution if you have a highly structured object.Upvoting this, given it's simplicity. In my use case I need to check all the attributes in an object for dodgy values-NaNs, nulls, undefined (they were points on a graph and these values prevented the graph from drawing). To get the value instead of the name, in the loop you would just do obj[someVariable]. Perhaps the reason it was downvoted so much is because it is not recursive. So this would not be an adequate solution if you have a highly structured object.Upvoting this, given it's simplicity. In my use case I need to check all the attributes in an object for dodgy values-NaNs, nulls, undefined (they were points on a graph and these values prevented the graph from drawing). To get the value instead of the name, in the loop you would just do obj[someVariable]. Perhaps the reason it was downvoted so much is because it is not recursive. So this would not be an adequate solution if you have a highly structured object.Upvoting this, given it's simplicity. In my use case I need to check all the attributes in an object for dodgy values-NaNs, nulls, undefined (they were points on a graph and these values prevented the graph from drawing). To get the value instead of the name, in the loop you would just do obj[someVariable]. Perhaps the reason it was downvoted so much is because it is not recursive. So this would not be an adequate solution if you have a highly structured object.Upvoting this, given it's simplicity. In my use case I need to check all the attributes in an object for dodgy values-NaNs, nulls, undefined (they were points on a graph and these values prevented the graph from drawing). To get the value instead of the name, in the loop you would just do obj[someVariable]. Perhaps the reason it was downvoted so much is because it is not recursive. So this would not be an adequate solution if you have a highly structured object." }; }, props: { title: String, }, computed: { changedItem() { return this.number + 1; }, }, template: '', methods: { buttonClicked() { bar(); }, }, }); new Vue({ el: '#vue-app-2', data: { label: 'Error in Vue-component', }, }); ``` -------------------------------- ### String Sanitization Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/06-sanitizer.md Demonstrates string sanitization, where strings are trimmed to a maximum of 200 characters and an ellipsis is added if truncation occurs. ```text Input: 'a' * 300 Output: 'aaa...' (200 chars + ellipsis) ``` -------------------------------- ### Enable Debug Mode Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Enable debug mode to get more information about potential issues. Set the `debug` option to `true` in your configuration. ```javascript debug: true ``` -------------------------------- ### Default Hawk Setup with Custom Endpoint Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/07-transport.md Demonstrates how to initialize the Hawk JavaScript SDK with a custom collector endpoint and configure connection idle timeout. The SDK automatically constructs the default endpoint using the integration ID from the provided token if no custom endpoint is specified. ```typescript import Catcher from '@hawk.so/browser'; // Automatically creates Socket with default settings const hawk = new Catcher({ token: 'YOUR_INTEGRATION_TOKEN', // Default: wss://{integrationId}.k1.hawk.so:443/ws // Override with custom endpoint: collectorEndpoint: 'wss://my-collector.example.com:443/ws', // Connection idle timeout (default 10000ms) reconnectionTimeout: 15000 }); ``` -------------------------------- ### Initialize Hawk SDK Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/INDEX.md Demonstrates how to initialize the Hawk SDK with a token. ```typescript const hawk = new Catcher('TOKEN'); ``` -------------------------------- ### Breadcrumb Storage Operations Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/08-types.md Demonstrates how to add a breadcrumb, retrieve all stored breadcrumbs, and clear the breadcrumb buffer using the BreadcrumbStore API. ```typescript hawk.breadcrumbs.add({ message: 'User action', type: 'user', level: 'info', data: { action: 'login' } }); const all = hawk.breadcrumbs.get(); hawk.breadcrumbs.clear(); ``` -------------------------------- ### Test SvelteKit Layout Rendering Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Render a SvelteKit layout component in a test environment. This example verifies that the layout renders without Hawk initialization issues in tests. ```typescript // src/routes/+layout.test.ts import { render } from '@testing-library/svelte'; import Layout from './+layout.svelte'; test('renders layout', () => { // Hawk won't be initialized in test environment const { container } = render(Layout); expect(container).toBeTruthy(); }); ``` -------------------------------- ### Set Affected User Information Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/08-types.md Example of how to set user information using the AffectedUser type. Custom fields like 'plan' and 'signup_date' can be included. ```typescript hawk.setUser({ id: 'user-12345', email: 'john@example.com', name: 'John Doe', plan: 'premium', signup_date: '2024-01-01' }); ``` -------------------------------- ### Get Catcher Version String Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/01-core-catcher.md Implement `getCatcherVersion` in subclasses to return the specific version string of the catcher, for example, '3.3.6'. ```typescript protected abstract getCatcherVersion(): string ``` -------------------------------- ### Configuration Reference Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Detailed explanation of initialization options, configuration settings, and default values. ```APIDOC ## Configuration Reference ### Description Comprehensive guide to configuring the Hawk JavaScript SDK. ### Initialization Options Details on the options available during SDK initialization. ### Full Reference Table A complete table listing all configuration options. ### All Configuration Options Detailed explanation of each configuration option. ### Default Values Information on the default values for configuration options. ### Environment Variables Note on the absence of environment variables for configuration. ### Production Setup Pattern Recommended setup for production environments. ### Development Setup Pattern Recommended setup for development environments. ### Testing Patterns Patterns for configuring the SDK in testing environments. ``` -------------------------------- ### Production Setup for Hawk JavaScript Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/09-configuration.md Configure Hawk for a production environment. It uses environment variables for sensitive information like tokens and versions, and includes custom logic for breadcrumbs and event sending. ```typescript const hawk = new Catcher({ token: process.env.HAWK_TOKEN!, release: process.env.APP_VERSION, context: { environment: 'production', deployment: process.env.DEPLOYMENT_ID }, user: getCurrentUser(), consoleTracking: true, breadcrumbs: { maxBreadcrumbs: 25, beforeBreadcrumb(bc) { // Exclude health checks if (bc.data?.url?.includes('/health')) { return false; } return bc; } }, beforeSend(event) { // Don't send 3rd-party script errors if (event.title === 'Script error.') { return false; } return event; } }); ``` -------------------------------- ### Development Setup for Hawk JavaScript Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/09-configuration.md Configure Hawk for a development environment. Enables debug mode, specifies a local collector endpoint, and increases breadcrumb limits for more detailed debugging. ```typescript const hawk = new Catcher({ token: 'development-token', release: 'dev', debug: true, collectorEndpoint: 'ws://localhost:3000/ws', breadcrumbs: { maxBreadcrumbs: 50, // More detail in dev beforeBreadcrumb: (bc) => bc // Keep all }, issues: { errors: true, longTasks: { thresholdMs: 50 }, webVitals: true } }); ``` -------------------------------- ### Hawk Initialization with SvelteKit Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Integrating Hawk JavaScript into a SvelteKit application for error tracking. ```javascript // src/routes/+layout.js or +layout.server.js import { Hawk } from "@hawk.js/sveltekit"; Hawk.init({ public_key: "YOUR_PUBLIC_KEY", // ... SvelteKit specific options }); ``` -------------------------------- ### Import Hawk Catcher Module Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/README.md Import the HawkCatcher class into your JavaScript or TypeScript code after installation. ```javascript import HawkCatcher from '@hawk.so/browser'; ``` -------------------------------- ### Initialize Hawk for Web Application Monitoring Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/README.md Initialize the Hawk SDK with essential configuration for tracking errors in production web applications, including user identification and environment context. ```typescript const hawk = new Catcher({ token: process.env.HAWK_TOKEN, release: process.env.APP_VERSION, user: getCurrentUser(), context: { environment: 'production' } }); ``` -------------------------------- ### Basic Configuration Options Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/09-configuration.md Required token for project identification and optional release version for filtering errors. ```typescript token: string ``` ```typescript release?: string ``` -------------------------------- ### Event Filtering with beforeSend Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/INDEX.md Provides an example of using the `beforeSend` hook to filter or modify events before they are sent. ```typescript beforeSend(event) { if (shouldIgnore(event)) return false; if (shouldModify(event)) event.context = {...}; return event; } ``` -------------------------------- ### Get BrowserBreadcrumbStore Instance Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Retrieve the singleton instance of the BrowserBreadcrumbStore. This is typically the first step before interacting with breadcrumb functionality. ```typescript import { BrowserBreadcrumbStore } from '@hawk.so/browser/addons/breadcrumbs'; const store = BrowserBreadcrumbStore.getInstance(); ``` -------------------------------- ### Get Catcher Type Identifier Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/01-core-catcher.md Implement `getCatcherType` in subclasses to return a unique identifier for the catcher type, such as 'errors/javascript'. ```typescript protected abstract getCatcherType(): T ``` -------------------------------- ### Get Current User Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/03-user-management.md Retrieve the current user. If no user is explicitly set, it generates and persists an anonymous ID. ```typescript const user = userManager.getUser(); // { id: "auto-generated-or-set-user-id" } ``` -------------------------------- ### Initialize Hawk.so in SvelteKit Root Layout Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Initialize the Hawk.so catcher in your root layout file (src/routes/+layout.svelte) to ensure it's available throughout your application. This should be done once when the app loads. ```typescript ``` -------------------------------- ### Common Hawk API Usage Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Illustrates common methods and patterns for interacting with the Hawk API after initialization. ```javascript import { Hawk } from "@hawk.js/hawk"; // Capture a specific error Hawk.captureException(new Error("Something went wrong")); // Add context to future errors Hawk.setContext({ userId: "user-123", version: "1.0.0" }); ``` -------------------------------- ### Navigation Breadcrumb Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Automatically captured when trackNavigation is enabled. Logs page navigation events with source and destination URLs. ```typescript { type: 'navigation', category: 'navigation', message: 'Navigated to https://example.com/dashboard', level: 'info', data: { from: 'https://example.com/home', to: 'https://example.com/dashboard' } } ``` -------------------------------- ### Initialize Hawk with Application Settings Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Initialize the Hawk Catcher with essential application details such as token, release version, and environment context. ```typescript import Catcher from '@hawk.so/browser'; export const hawk = new Catcher({ token: process.env.REACT_APP_HAWK_TOKEN, release: process.env.REACT_APP_VERSION, context: { environment: process.env.NODE_ENV } }); ``` -------------------------------- ### XHR Request Breadcrumb Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Automatically captured when trackFetch is enabled. Similar to fetch requests, it logs XHR activity. ```typescript { type: 'request', category: 'xhr', message: '200 GET https://api.example.com/posts', level: 'info' | 'error', data: { url: 'https://api.example.com/posts', method: 'GET', statusCode: 200, durationMs: 200 } } ``` -------------------------------- ### Add, Get, and Clear Breadcrumbs Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/INDEX.md Demonstrates how to manually add breadcrumbs, retrieve all existing breadcrumbs, and clear the breadcrumb trail. ```typescript // Add manual breadcrumb hawk.breadcrumbs.add({ message: 'User action', type: 'user', data: { action: 'login' } }); // Get all breadcrumbs const trail = hawk.breadcrumbs.get(); // Clear trail hawk.breadcrumbs.clear(); ``` -------------------------------- ### Initialize Hawk for SPA Development Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/README.md Configure the Hawk SDK for single-page applications to monitor performance metrics like Web Vitals and long tasks, and track navigation events. ```typescript const hawk = new Catcher({ token: 'TOKEN', issues: { webVitals: true, longTasks: true }, breadcrumbs: { trackNavigation: true } }); ``` -------------------------------- ### Configure Release and Context in SvelteKit Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Configure Hawk.so with release version and custom context information during initialization. This helps in categorizing and filtering errors based on environment, build, or region. ```typescript ``` -------------------------------- ### Initialize Catcher with Full Configuration Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/02-browser-catcher.md Configure the Catcher with a detailed settings object for advanced options like release version, user information, context, and specific issue tracking. ```typescript const hawk = new Catcher({ token: 'YOUR_INTEGRATION_TOKEN', release: '1.0.0', user: { id: 'user-123', email: 'user@example.com' }, context: { environment: 'production' }, debug: false, consoleTracking: true, breadcrumbs: { maxBreadcrumbs: 20 }, issues: { errors: true, longTasks: { thresholdMs: 100 }, webVitals: true } }); ``` -------------------------------- ### Get Auto-Captured Navigation Breadcrumb Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Retrieve auto-captured navigation breadcrumbs. This tracks client-side route changes within your single-page application. ```javascript hawk.breadcrumbs.get(); // Shows: // { // type: 'navigation', // category: 'navigation', // message: 'Navigated to https://example.com/dashboard', // level: 'info', // data: { from: '...', to: '...' } // } ``` -------------------------------- ### Hawk SDK Full Configuration Options Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Configure the Hawk SDK with various options including token, version tracking, user identification, global context, features, and hooks. ```typescript const hawk = new Catcher({ token: 'YOUR_INTEGRATION_TOKEN', // Version tracking release: '1.2.3', // User identification user: { id: 'user-123', email: 'user@example.com' }, // Global context context: { environment: 'production' }, // Features debug: false, consoleTracking: true, breadcrumbs: { maxBreadcrumbs: 20 }, issues: { errors: true, webVitals: true }, // Hooks beforeSend: (event) => event, // Frameworks vue: vueApp }); ``` -------------------------------- ### vue Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/02-browser-catcher.md Vue.js integration instance. Set via `connectVue()` method or via constructor settings. ```APIDOC ## vue ### Description Vue.js integration instance. Set via `connectVue()` method or via constructor settings. ### Type - **vue** (VueIntegration | null) ``` -------------------------------- ### Get Breadcrumb Snapshot Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Retrieve a copy of all currently recorded breadcrumbs, ordered from oldest to newest. Useful for inspecting the event trail. ```typescript const breadcrumbs = hawk.breadcrumbs.get(); console.log(`${breadcrumbs.length} breadcrumbs recorded`); breadcrumbs.forEach(bc => { console.log(`[${bc.timestamp}] ${bc.message}`); }); ``` -------------------------------- ### Initialize HawkUserManager Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/03-user-management.md Instantiate HawkUserManager with storage and random generator implementations. Use HawkLocalStorage and BrowserRandomGenerator for browser environments. ```typescript import { HawkUserManager } from '@hawk.so/core'; import { HawkLocalStorage } from '@hawk.so/browser'; import { BrowserRandomGenerator } from '@hawk.so/browser'; const userManager = new HawkUserManager( new HawkLocalStorage(), new BrowserRandomGenerator() ); ``` -------------------------------- ### Initialize Hawk Catcher in React Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/README.md Instantiate the Hawk Catcher with your integration token. This setup is suitable for the main entry point of a React application. ```javascript import HawkCatcher from '@hawk.so/browser'; const hawk = new HawkCatcher({ token: 'INTEGRATION_TOKEN' }); ``` -------------------------------- ### Load Hawk from CDN Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/README.md Include the Hawk script directly in your HTML using a CDN link. Ensure you use a specific version to avoid breaking changes. ```html ``` -------------------------------- ### Browser Breadcrumb Store Singleton Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/COVERAGE.txt Documentation for the BrowserBreadcrumbStore singleton, including its methods, auto-capture behavior, and configuration. ```APIDOC ## BrowserBreadcrumbStore Singleton ### Description Manages breadcrumbs in the browser environment. ### All Methods Documented Comprehensive documentation for all methods of the BrowserBreadcrumbStore. ### Auto-capture Behavior Explanation of how breadcrumbs are automatically captured. ### beforeBreadcrumb Hook Details on the `beforeBreadcrumb` hook for customizing breadcrumb capture. ### Breadcrumb Types Description of different breadcrumb types. ### Configuration Options Available configuration options for the breadcrumb store. ### Complete Setup Examples Examples demonstrating the complete setup of the breadcrumb store. ``` -------------------------------- ### Custom Transport Implementation Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/09-configuration.md Implement a custom transport mechanism for sending messages, overriding the default WebSocket transport. Example uses `fetch`. ```typescript transport?: Transport<'errors/javascript'> ``` ```typescript const customTransport = { async send(message) { await fetch('/api/errors', { method: 'POST', body: JSON.stringify(message) }); } }; const hawk = new Catcher({ token: 'YOUR_TOKEN', transport: customTransport }); ``` -------------------------------- ### Click Event Breadcrumb Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Automatically captured when trackClicks is enabled. Logs UI click interactions, including element selector and text. ```typescript { type: 'ui', category: 'ui.click', message: 'Click on button.submit', level: 'info', data: { selector: 'button.submit', text: 'Submit Form', tagName: 'BUTTON' } } ``` -------------------------------- ### connectVue() Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/02-browser-catcher.md Initialize Vue.js error handling. Attaches error handler to Vue app. ```APIDOC ## connectVue() ### Description Initialize Vue.js error handling. Attaches error handler to Vue app. ### Method `connectVue(vue): void` ### Parameters #### Path Parameters - **vue** (VueApp) - Required - Vue application instance. ### Example ```typescript import { createApp } from 'vue'; const app = createApp(MyComponent); hawk.connectVue(app); ``` ``` -------------------------------- ### Get Auto-Captured Network Breadcrumb Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/00-quick-start.md Retrieve auto-captured network request breadcrumbs. This shows details about outgoing HTTP requests made by the browser. ```javascript hawk.breadcrumbs.get(); // Shows: // { // type: 'request', // category: 'fetch', // message: '200 GET https://api.example.com/users', // level: 'info', // data: { url, method, statusCode, durationMs } // } ``` -------------------------------- ### Catcher Configuration Options Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/INDEX.md Provides a quick reference for the configuration options available when initializing the Catcher class. ```typescript new Catcher({ // Required token: string, // Version & identity release?: string, user?: AffectedUser, // Context context?: EventContext, // Features debug?: boolean, consoleTracking?: boolean, breadcrumbs?: false | BreadcrumbsOptions, issues?: false | IssuesOptions, // Hooks & filters beforeSend?: (event) => event | false | void, // Transport collectorEndpoint?: string, reconnectionTimeout?: number, transport?: Transport, // Frameworks vue?: VueApp, disableVueErrorHandler?: boolean }) ``` -------------------------------- ### Initialize Hawk in Client Hooks Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/sveltekit/README.md Initialize the Hawk SDK in your SvelteKit application's client-side hooks. Ensure you replace 'YOUR_INTEGRATION_TOKEN' with your actual Hawk integration token. ```typescript import Hawk from '@hawk.so/sveltekit'; new Hawk({ token: 'YOUR_INTEGRATION_TOKEN' }); ``` -------------------------------- ### Example: Filtering and Modifying Breadcrumbs Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/04-breadcrumbs.md Demonstrates how to use the beforeBreadcrumb hook to filter out specific analytics requests and redact sensitive information from request breadcrumbs. ```javascript const hawk = new Catcher({ token: 'YOUR_TOKEN', breadcrumbs: { beforeBreadcrumb(breadcrumb, hint) { // Drop analytics requests if (breadcrumb.category === 'fetch' && breadcrumb.data?.url?.includes('analytics')) { return false; } // Remove sensitive headers from request breadcrumbs if (breadcrumb.type === 'request' && breadcrumb.data?.headers?.Authorization) { breadcrumb.data.headers.Authorization = '[REDACTED]'; } return breadcrumb; } } }); ``` -------------------------------- ### Send Test Event with Hawk JavaScript Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/example/index.html Use `hawk.test()` to send a test event to verify the catcher is working correctly. This is useful for initial setup and debugging. ```javascript hawk.test() ``` -------------------------------- ### Clear Breadcrumbs with Hawk JavaScript Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/example/index.html Remove all recorded breadcrumbs using `hawk.clear_breadcrumbs()`. This is useful for resetting the breadcrumb trail, for example, when navigating to a new section of the application. ```javascript hawk.clear_breadcrumbs(); ``` -------------------------------- ### Initialize Hawk for SvelteKit Performance Monitoring Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Configure Hawk to monitor Core Web Vitals in your SvelteKit application. Set thresholds for LCP, CLS, and INP to report poor performance. ```typescript ``` -------------------------------- ### test() Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/01-core-catcher.md Sends a test event from the client to verify Hawk integration is working. ```APIDOC ## test() ### Description Sends a test event from the client to verify Hawk integration is working. ### Method `public test(): void` ### Example ```typescript hawk.test(); ``` ``` -------------------------------- ### Set Event Context Data Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/08-types.md Example of setting contextual data for events. This includes environment, version, region, user/session IDs, and custom nested data. ```typescript hawk.setContext({ environment: 'production', version: '1.2.3', region: 'us-west-1', userId: 'user-123', sessionId: 'sess-456', customData: { plan: 'premium', features: ['feature1', 'feature2'] } }); ``` -------------------------------- ### Array Sanitization Example Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/06-sanitizer.md Shows array sanitization, limiting the number of items to 10. Additional items are represented by a placeholder indicating the count of omitted items. ```text Input: [0, 1, 2, ..., 50] Output: [0, 1, 2, ..., 9, '<41 more items...>'] ``` -------------------------------- ### Register and Use Custom Map Sanitizer Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/06-sanitizer.md Example of creating and registering a custom handler for Map objects. This handler converts Map entries into a plain object. ```typescript const mapHandler: SanitizerTypeHandler = { check: (value) => value instanceof Map, format: (map) => { const obj = {}; for (const [key, val] of map.entries()) { obj[String(key)] = val; } return obj; } }; Sanitizer.registerHandler(mapHandler); const data = { myMap: new Map([['key1', 'value1'], ['key2', 'value2']]) }; Sanitizer.sanitize(data); // { myMap: { key1: 'value1', key2: 'value2' } } ``` -------------------------------- ### Set and Clear User Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/INDEX.md Shows how to set the current user's information upon login and clear it upon logout. ```typescript // On login hawk.setUser({ id: 'user-123', email: 'user@example.com' }); // On logout hawk.clearUser(); ``` -------------------------------- ### Create a Shared Hawk Instance Source: https://github.com/codex-team/hawk.javascript/blob/master/_autodocs/12-sveltekit-integration.md Initialize a singleton Hawk instance in a shared module for consistent error tracking across your SvelteKit application. This instance can be imported and used in any component or server module. ```typescript // src/lib/hawk.ts import Catcher from '@hawk.so/sveltekit'; export const hawk = new Catcher({ token: import.meta.env.VITE_HAWK_TOKEN, release: import.meta.env.VITE_APP_VERSION, context: { environment: import.meta.env.MODE } }); ``` -------------------------------- ### Filter Sensitive Data with beforeSend Hook Source: https://github.com/codex-team/hawk.javascript/blob/master/packages/browser/README.md Use the `beforeSend` hook to filter out sensitive information from events before they are sent to Hawk. This example removes the user's name. ```javascript window.hawk = new HawkCatcher({ token: 'INTEGRATION TOKEN', beforeSend(event) { if (event.user && event.user.name) { delete event.user.name; } return event; } }) ```