1
1
<script lang="ts" setup>
2
2
import { onDevtoolsClientConnected } from ' @nuxt/devtools-kit/iframe-client'
3
3
import { registry } from ' ../src/registry'
4
- import { devtools , getScriptSize , humanFriendlyTimestamp , reactive , ref , urlToOrigin } from ' #imports'
4
+ import { devtools , fetchScript , humanFriendlyTimestamp , reactive , ref , urlToOrigin } from ' #imports'
5
5
import { msToHumanReadable } from ' ~/utils/formatting'
6
6
7
7
const scriptRegistry = await registry ()
8
8
9
9
const scripts = ref ({})
10
10
const scriptSizes = reactive <Record <string , string >>({})
11
+ const scriptErrors = reactive <Record <string , string >>({})
11
12
12
13
function syncScripts(_scripts : any []) {
13
14
// augment the scripts with registry
@@ -26,13 +27,17 @@ function syncScripts(_scripts: any[]) {
26
27
}
27
28
const scriptSizeKey = script .src
28
29
if (! scriptSizes [scriptSizeKey ]) {
29
- getScriptSize (script .src ).then ((size ) => {
30
- scriptSizes [scriptSizeKey ] = size
31
- script .size = size
32
- }).catch (() => {
33
- script .size = ' '
34
- scriptSizes [scriptSizeKey ] = ' '
35
- })
30
+ fetchScript (script .src )
31
+ .then ((res ) => {
32
+ if (res .size ) {
33
+ scriptSizes [scriptSizeKey ] = res .size
34
+ script .size = res .size
35
+ }
36
+ if (res .error ) {
37
+ scriptErrors [scriptSizeKey ] = res .error
38
+ script .error = res .error
39
+ }
40
+ })
36
41
}
37
42
return [key , script ]
38
43
}),
@@ -192,7 +197,12 @@ function viewDocs(docs: string) {
192
197
Status
193
198
</div >
194
199
<div class =" capitalize" >
195
- {{ script.$script.status.value }}
200
+ <div v-if =" scriptErrors[script.src]" >
201
+ {{ scriptErrors[script.src] === 'TypeError: Failed to fetch' ? 'CORS Error' : scriptErrors[script.src] }}
202
+ </div >
203
+ <div v-else >
204
+ {{ script.$script.status }}
205
+ </div >
196
206
</div >
197
207
</div >
198
208
<div v-if =" scriptSizes[script.src]" >
0 commit comments