@@ -12,22 +12,27 @@ import {
1212 unregisterContentScriptIfExists ,
1313} from "./dynamic_content_scripts" ;
1414
15- async function main ( ) : Promise < void > {
16- browser . runtime . onMessage . addListener ( handleMessages ) ;
17-
18- sentryInit ( {
19- dsn : process . env . SENTRY_DSN ,
20-
21- integrations : [
22- browserTracingIntegration ( {
23- // disable automatic span creation
24- instrumentNavigation : false ,
25- instrumentPageLoad : false ,
26- } ) ,
27- ] ,
15+ async function handleConsent ( ) : Promise < void > {
16+ const consent = await new Codecov ( ) . getConsent ( ) ;
17+ if ( ! consent ) {
18+ const url = browser . runtime . getURL ( "consent.html" ) ;
19+ await browser . tabs . create ( { url, active : true } ) ;
20+ }
21+ }
2822
29- tracesSampleRate : 1.0 ,
23+ async function main ( ) : Promise < void > {
24+ browser . runtime . onInstalled . addListener ( async ( { reason, temporary } ) => {
25+ switch ( reason ) {
26+ case "install" : {
27+ await handleConsent ( ) ;
28+ }
29+ case "update" : {
30+ await handleConsent ( ) ;
31+ }
32+ }
3033 } ) ;
34+
35+ browser . runtime . onMessage . addListener ( handleMessages ) ;
3136}
3237
3338async function handleMessages ( message : {
@@ -36,6 +41,25 @@ async function handleMessages(message: {
3641 referrer ?: string ;
3742} ) {
3843 const codecov = new Codecov ( ) ;
44+ if ( await codecov . getConsent ( ) ) {
45+ console . log ( "Have data consent, initializing Sentry" ) ;
46+ sentryInit ( {
47+ dsn : process . env . SENTRY_DSN ,
48+
49+ integrations : [
50+ browserTracingIntegration ( {
51+ // disable automatic span creation
52+ instrumentNavigation : false ,
53+ instrumentPageLoad : false ,
54+ } ) ,
55+ ] ,
56+
57+ tracesSampleRate : 1.0 ,
58+ } ) ;
59+ } else {
60+ console . log ( "Do not have data consent, not initializing Sentry" ) ;
61+ }
62+
3963 return startSpan ( { name : message . type } , async ( ) => {
4064 switch ( message . type ) {
4165 case MessageType . FETCH_COMMIT_REPORT :
@@ -48,6 +72,10 @@ async function handleMessages(message: {
4872 return codecov . listComponents ( message . payload , message . referrer ! ) ;
4973 case MessageType . CHECK_AUTH :
5074 return codecov . checkAuth ( message . payload ) ;
75+ case MessageType . GET_CONSENT :
76+ return codecov . getConsent ( ) ;
77+ case MessageType . SET_CONSENT :
78+ return codecov . setConsent ( message . payload ) ;
5179 case MessageType . REGISTER_CONTENT_SCRIPTS :
5280 return registerContentScript ( message . payload ) ;
5381 case MessageType . UNREGISTER_CONTENT_SCRIPTS :
0 commit comments