@@ -8,23 +8,25 @@ browser.tabs.onUpdated.addListener(handleUpdated)
8
8
browser . runtime . onMessage . addListener (
9
9
async function ( message , sender , sendResponse ) {
10
10
if ( message . action === 'analyze' ) {
11
+ // when sending message from popup.js there's no sender.tab, so need to pass tabId
12
+ const tabId = ( sender . tab && sender . tab . id ) || message . payload . tabId
11
13
browser . browserAction . setIcon ( {
12
- tabId : sender . tab . id ,
14
+ tabId : tabId ,
13
15
path : message . payload . hasVue ? 'icons/icon-128.png' : 'icons/icon-grey-128.png'
14
16
} )
15
17
16
- if ( ! tabsStorage [ sender . tab . id ] ) {
17
- tabsStorage [ sender . tab . id ] = message . payload
18
+ if ( ! tabsStorage [ tabId ] ) {
19
+ tabsStorage [ tabId ] = message . payload
18
20
} else {
19
21
// temporary fix when hit CSP
20
22
if ( ! message . payload . modules . length ) delete message . payload . modules
21
23
if ( ! message . payload . plugins . length ) delete message . payload . plugins
22
24
23
- tabsStorage [ sender . tab . id ] = { ...tabsStorage [ sender . tab . id ] , ...message . payload }
25
+ tabsStorage [ tabId ] = { ...tabsStorage [ tabId ] , ...message . payload }
24
26
}
25
27
26
- const showcase = tabsStorage [ sender . tab . id ]
27
- if ( showcase . hasVue && ! showcase . slug ) {
28
+ const showcase = tabsStorage [ tabId ]
29
+ if ( showcase . hasVue ) {
28
30
try {
29
31
const res = await fetch ( `https://vuetelemetry.com/api/analyze?url=${ message . payload . url } ` , {
30
32
method : 'GET'
@@ -47,7 +49,7 @@ browser.runtime.onMessage.addListener(
47
49
}
48
50
} catch ( err ) { }
49
51
}
50
- // tabsStorage[sender.tab.id ] = message.payload
52
+ // tabsStorage[tabId ] = message.payload
51
53
} else if ( ! sender . tab ) {
52
54
if ( message . action === 'getShowcase' ) {
53
55
// this is likely popup requesting
0 commit comments