@@ -28,25 +28,55 @@ browser.runtime.onMessage.addListener(
28
28
const showcase = tabsStorage [ tabId ]
29
29
if ( showcase . hasVue && ! showcase . slug ) {
30
30
try {
31
- const res = await fetch ( `https://vuetelemetry.com/api/analyze?url=${ message . payload . url } ` , {
32
- method : 'GET'
33
- } )
34
- . then ( ( response ) => {
35
- if ( ! response . ok ) {
31
+ if ( typeof EventSource === 'undefined' ) {
32
+ console . log ( 'EventSource is not supported in current borwser!' )
33
+ return
34
+ }
35
+ const sse = new EventSource (
36
+ `https://service.vuetelemetry.com?url=${ message . payload . url } `
37
+ )
38
+ sse . addEventListener ( 'message' , ( event ) => {
39
+ try {
40
+ const res = JSON . parse ( event . data )
41
+ if ( ! res . error && ! res . isAdultContent ) {
42
+ showcase . isPublic = res . isPublic
43
+ showcase . slug = res . slug
44
+ sse . close ( )
45
+
46
+ // temporary fix when hit CSP
47
+ if ( ! showcase . modules . length && res . modules . length ) {
48
+ showcase . modules = res . modules
49
+ }
50
+ if ( ! showcase . plugins . length && res . plugins . length ) {
51
+ showcase . plugins = res . plugins
52
+ }
53
+ } else {
36
54
throw new Error ( 'API call to VT failed' )
37
55
}
38
- return response . json ( )
39
- } )
40
- showcase . isPublic = res . body . isPublic
41
- showcase . slug = res . body . slug
56
+ } catch ( err ) {
57
+ sse . close ( )
58
+ }
59
+ } )
42
60
43
- // temporary fix when hit CSP
44
- if ( ! showcase . modules . length && res . body . modules . length ) {
45
- showcase . modules = res . body . modules
46
- }
47
- if ( ! showcase . plugins . length && res . body . plugins . length ) {
48
- showcase . plugins = res . body . plugins
49
- }
61
+ // const res = await fetch(`https://vuetelemetry.com/api/analyze?url=${message.payload.url}`, {
62
+ // method: 'GET'
63
+ // })
64
+ // .then((response) => {
65
+ // if (!response.ok) {
66
+ // throw new Error('API call to VT failed')
67
+ // }
68
+ // return response.json()
69
+ // })
70
+ // showcase.isPublic = res.body.isPublic
71
+ // showcase.slug = res.body.slug
72
+
73
+ // // temporary fix when hit CSP
74
+ // if (!showcase.modules.length && res.body.modules.length) {
75
+ // showcase.modules = res.body.modules
76
+ // }
77
+ // if (!showcase.plugins.length && res.body.plugins.length) {
78
+ // showcase.plugins = res.body.plugins
79
+ // }
50
80
} catch ( err ) { }
51
81
}
52
82
// tabsStorage[tabId] = message.payload
0 commit comments