@@ -23,8 +23,8 @@ const setDelayedAction = async (name, tabId) => {
2323 if ( secondsToNextBlock && secondsToNextBlock < secondsToLimit ) {
2424 secondsLeft = secondsToNextBlock ;
2525 }
26- delayHandler = setTimeout ( ( ) => {
27- chrome . tabs . remove ( tabId ) ;
26+ delayHandler = setTimeout ( async ( ) => {
27+ await chrome . tabs . remove ( tabId ) ;
2828 utils . notify ( `You can no longer be on ${ name } ` ) ;
2929 } , secondsLeft * 1000 ) ;
3030 }
@@ -38,10 +38,10 @@ const setActive = async () => {
3838 if ( utils . isTabAMatch ( name , cacheStorage . configuration ) ) {
3939 if ( utils . isTimeExceeded ( cacheStorage , name ) ) {
4040 // eslint-disable-next-line
41- chrome . tabs . remove ( id ) ;
41+ await chrome . tabs . remove ( id ) ;
4242 } else if ( utils . isTimeframeBlocked ( cacheStorage , name ) ) {
4343 // eslint-disable-next-line
44- chrome . tabs . remove ( id ) ;
44+ await chrome . tabs . remove ( id ) ;
4545 } else if ( cacheStorage . active . name !== name ) {
4646 // if a different site is active then end the existing site's session
4747 utils . end ( cacheStorage ) ;
@@ -79,10 +79,12 @@ const synchronize = async (fetchData = false) => {
7979
8080 // eslint-disable-next-line
8181 chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
82- const { url } = tab ;
83- const name = utils . getName ( url ) ;
84- if ( cacheStorage . active . name !== name ) {
85- setActive ( ) ;
82+ if ( tab ) {
83+ const { url } = tab ;
84+ const name = utils . getName ( url ) ;
85+ if ( cacheStorage . active . name !== name ) {
86+ setActive ( ) ;
87+ }
8688 }
8789 } ) ;
8890
@@ -106,17 +108,17 @@ const synchronize = async (fetchData = false) => {
106108 } ) ;
107109
108110 // eslint-disable-next-line
109- chrome . notifications . onButtonClicked . addListener ( ( notificationId , buttonIndex ) => {
111+ chrome . notifications . onButtonClicked . addListener ( async ( notificationId , buttonIndex ) => {
110112 if ( buttonIndex === 0 ) {
111113 // close the tab
112114 // eslint-disable-next-line
113- chrome . tabs . query ( {
115+ const activeTab = await chrome . tabs . query ( {
114116 active : true ,
115117 currentWindow : true
116- } , ( activeTab ) => {
117- // eslint-disable-next-line
118- chrome . tabs . remove ( activeTab [ 0 ] . id ) ;
119118 } ) ;
119+ if ( activeTab [ 0 ] ) {
120+ await chrome . tabs . remove ( activeTab [ 0 ] . id ) ;
121+ }
120122 }
121123 } ) ;
122124
0 commit comments