11<script lang="ts" setup>
22import { onDevtoolsClientConnected } from ' @nuxt/devtools-kit/iframe-client'
33import { registry } from ' ../src/registry'
4- import { devtools , getScriptSize , humanFriendlyTimestamp , reactive , ref , urlToOrigin } from ' #imports'
4+ import { devtools , fetchScript , humanFriendlyTimestamp , reactive , ref , urlToOrigin } from ' #imports'
55import { msToHumanReadable } from ' ~/utils/formatting'
66
77const scriptRegistry = await registry ()
88
99const scripts = ref ({})
1010const scriptSizes = reactive <Record <string , string >>({})
11+ const scriptErrors = reactive <Record <string , string >>({})
1112
1213function syncScripts(_scripts : any []) {
1314 // augment the scripts with registry
@@ -26,13 +27,17 @@ function syncScripts(_scripts: any[]) {
2627 }
2728 const scriptSizeKey = script .src
2829 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+ })
3641 }
3742 return [key , script ]
3843 }),
@@ -192,7 +197,12 @@ function viewDocs(docs: string) {
192197 Status
193198 </div >
194199 <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 >
196206 </div >
197207 </div >
198208 <div v-if =" scriptSizes[script.src]" >
0 commit comments