@@ -6,6 +6,7 @@ import "tether-drop/dist/css/drop-theme-arrows.css";
66import "src/basscss.css" ;
77import "./style.css" ;
88import {
9+ Consent ,
910 CoverageStatus ,
1011 FileCoverageReport ,
1112 FileCoverageReportResponse ,
@@ -32,7 +33,7 @@ import {
3233 getConsent ,
3334} from "../common/fetchers" ;
3435import { print } from "src/utils" ;
35- import Sentry from "../../common/sentry" ;
36+ import { initSentry } from "../../common/sentry" ;
3637
3738const globals : {
3839 coverageReport ?: FileCoverageReport ;
@@ -44,23 +45,31 @@ const globals: {
4445 prompt ?: HTMLElement ;
4546} = { } ;
4647
47- init ( ) ;
48+ let Sentry : ReturnType < typeof initSentry > = undefined ;
49+ let consent : Consent = "none" ;
50+
51+ await init ( ) ;
52+
53+ async function init ( ) : Promise < void > {
54+ consent = await getConsent ( ) ;
55+
56+ Sentry = initSentry ( consent ) ;
4857
49- function init ( ) : Promise < void > {
5058 // this event discovered by "reverse-engineering GitHub"
5159 // https://github.com/refined-github/refined-github/blob/main/contributing.md#reverse-engineering-github
5260 // TODO: this event is not fired when navigating using the browser's back and forward buttons
5361 document . addEventListener ( "soft-nav:end" , ( ) => {
5462 clear ( ) ;
55- main ( ) ;
63+ main ( consent ) ;
5664 } ) ;
5765
58- return main ( ) ;
66+ return main ( consent ) ;
5967}
6068
61- async function main ( ) : Promise < void > {
69+ async function main ( consent : Consent ) : Promise < void > {
6270 try {
63- if ( ! ( await getConsent ( ) ) ) {
71+ if ( consent === "none" ) {
72+ // No data consent, do nothing.
6473 return ;
6574 }
6675
@@ -72,7 +81,9 @@ async function main(): Promise<void> {
7281 globals . coverageButton = createCoverageButton ( ) ;
7382 await process ( urlMetadata ) ;
7483 } catch ( e ) {
75- Sentry . captureException ( e ) ;
84+ if ( Sentry ) {
85+ Sentry . captureException ( e ) ;
86+ }
7687 throw e ;
7788 }
7889}
@@ -314,7 +325,7 @@ async function handleFlagClick(selectedFlags: string[]) {
314325 [ flagsStorageKey ] : selectedFlags ,
315326 } ) ;
316327 clear ( ) ;
317- await main ( ) ;
328+ await main ( consent ) ;
318329}
319330
320331async function handleComponentClick ( selectedComponents : string [ ] ) {
@@ -325,7 +336,7 @@ async function handleComponentClick(selectedComponents: string[]) {
325336 [ componentsStorageKey ] : selectedComponents ,
326337 } ) ;
327338 clear ( ) ;
328- await main ( ) ;
339+ await main ( consent ) ;
329340}
330341
331342function calculateCoveragePct ( coverageReport : FileCoverageReport ) : number {
0 commit comments