Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Webdriverio Webdriverio CrashReporter Class

From Leeroopedia
Revision as of 11:57, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Webdriverio_Webdriverio_CrashReporter_Class.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains BrowserStack, Error_Reporting
Last Updated 2026-02-12 00:00 GMT

Overview

The CrashReporter class handles crash reporting with PII filtering and key redaction for BrowserStack analytics, ensuring that service errors are reported without exposing sensitive user data.

Description

CrashReporter is a static utility class responsible for collecting, sanitizing, and uploading crash reports to BrowserStack's analytics endpoint (/api/v1/analytics). It maintains two static properties: userConfigForReporting (sanitized test configuration) and credentialsForCrashReportUpload (authentication credentials). The setConfigDetails method initializes these by filtering PII from the user config (removing user/key fields, redacting extensions in capabilities) and serializing them to environment variables for cross-process access. The uploadCrashReport method sends exception data along with the hashed build ID, framework version, and sanitized config. Key privacy methods include recursivelyRedactKeysFromObject for replacing sensitive key values with [REDACTED], deletePIIKeysFromObject for removing user/key properties entirely, and filterCapabilities/filterPII for comprehensive sanitization.

Usage

Use this class to report internal service errors to BrowserStack analytics. It is initialized in the BrowserstackLauncherService constructor and invoked throughout the service whenever an unexpected error occurs in observability-related operations.

Code Reference

Source Location

Signature

export default class CrashReporter {
    public static userConfigForReporting: UserConfigforReporting
    private static credentialsForCrashReportUpload: CredentialsForCrashReportUpload

    static setCredentialsForCrashReportUpload(
        options: BrowserstackConfig & Options.Testrunner,
        config: Options.Testrunner
    ): void

    static setConfigDetails(
        userConfig: Options.Testrunner,
        capabilities: Capabilities.TestrunnerCapabilities,
        options: BrowserstackConfig & Options.Testrunner
    ): void

    static async uploadCrashReport(exception: string, stackTrace: string): Promise<void>

    static recursivelyRedactKeysFromObject(
        obj: Dict | Array<Dict>,
        keys: string[]
    ): void

    static deletePIIKeysFromObject(obj: { [key: string]: unknown }): void

    static filterCapabilities(capabilities: Capabilities.TestrunnerCapabilities): Capabilities.TestrunnerCapabilities

    static filterPII(userConfig: Options.Testrunner): Options.Testrunner
}

Import

import CrashReporter from './crash-reporter.js'

I/O Contract

Inputs

Name Type Required Description
userConfig Options.Testrunner Yes WebdriverIO configuration to be sanitized and stored for crash reports
capabilities Capabilities.TestrunnerCapabilities Yes Test capabilities to be filtered (extensions redacted)
options BrowserstackConfig & Options.Testrunner Yes Service options for extracting observability user/key credentials
exception string Yes Error message to include in the crash report
stackTrace string Yes Stack trace of the error

Outputs

Name Type Description
Crash report API call HTTP POST to /api/v1/analytics Sends hashed_id, observability_version, exception, and sanitized config
process.env.CREDENTIALS_FOR_CRASH_REPORTING string JSON-serialized credentials for cross-process crash reporting
process.env.USER_CONFIG_FOR_REPORTING string JSON-serialized sanitized config for cross-process access

Usage Examples

Initializing crash reporter in launcher

// In BrowserstackLauncherService constructor
try {
    CrashReporter.setConfigDetails(this._config, capabilities, this._options)
} catch (error: unknown) {
    BStackLogger.error(`[Crash_Report_Upload] Config processing failed due to ${error}`)
}

Uploading a crash report on error

// In service error handlers
try {
    // ... some operation
} catch (err) {
    CrashReporter.uploadCrashReport(
        `Error in service class before function: ${err}`,
        (err as Error).stack || 'unknown error'
    )
}

Redacting sensitive config keys

const configCopy = JSON.parse(JSON.stringify(config))
CrashReporter.recursivelyRedactKeysFromObject(
    configCopy,
    ['user', 'key', 'accesskey', 'password']
)
// configCopy.user === '[REDACTED]'
// configCopy.key === '[REDACTED]'

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment