Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ignoring browser extension errors #3

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/js/src/Flare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Flare {
stage: '',
maxGlowsPerReport: 30,
reportingUrl: 'https://reporting.flareapp.io/api/reports',
reportBrowserExtensionErrors: false,
sebastiandedeyne marked this conversation as resolved.
Show resolved Hide resolved
debug: false,
beforeEvaluate: (error) => error,
beforeSubmit: (report) => report,
Expand Down Expand Up @@ -183,7 +184,12 @@ export class Flare {
return;
}

return this.http.report(reportToSubmit, this.config.reportingUrl, this.config.key);
return this.http.report(
reportToSubmit,
this.config.reportingUrl,
this.config.key,
this.config.reportBrowserExtensionErrors
);
}

// Deprecated, the following methods exist for backwards compatibility.
Expand Down
5 changes: 3 additions & 2 deletions packages/js/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Report } from '../types';
import { flatJsonStringify } from '../util';

export class Api {
report(report: Report, url: string, key: string): Promise<void> {
report(report: Report, url: string, key: string, reportBrowserExtensionErrors: boolean): Promise<void> {
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Token': key,
'X-Requested-With': 'XMLHttpRequest',
'x-api-token': key,
'X-Report-Browser-Extension-Errors': JSON.stringify(reportBrowserExtensionErrors),
},
body: flatJsonStringify({
...report,
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type Config = {
sourcemapVersion: string;
stage: string;
maxGlowsPerReport: number;
reportBrowserExtensionErrors: boolean;
reportingUrl: string;
debug: boolean;
beforeEvaluate: (error: Error) => Error | false | null | Promise<Error | false | null>;
Expand Down
16 changes: 11 additions & 5 deletions packages/js/tests/helpers/FakeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { Report } from '../../src/types';
export class FakeApi extends Api {
reports: Report[] = [];

report(report: Report): Promise<void> {
lastReport?: Report;
lastUrl?: string;
lastKey?: string;
lastReportBrowserExtensionErrors?: boolean;

report(report: Report, url: string, key: string, reportBrowserExtensionErrors: boolean): Promise<void> {
this.reports.push(report);

return Promise.resolve();
}
this.lastUrl = url;
this.lastKey = key;
this.lastReportBrowserExtensionErrors = reportBrowserExtensionErrors;
this.lastReport = report;

get lastReport(): Report | undefined {
return this.reports[this.reports.length - 1];
return Promise.resolve();
}
}
14 changes: 14 additions & 0 deletions packages/js/tests/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ test('report the test message', async () => {
expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('The Flare client is set up correctly!');
});

test('does not report browser extension errors by default', async () => {
await client.test();

expect(fakeHttp.lastReportBrowserExtensionErrors).toBe(false);
});

test('can be configured to report browser extension errors', async () => {
client.configure({ reportBrowserExtensionErrors: true });

await client.test();

expect(fakeHttp.lastReportBrowserExtensionErrors).toBe(true);
});