Skip to content

Commit

Permalink
fix: improve client injection error message
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 28, 2023
1 parent cb5ddc6 commit de9baa3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/devtools/src/runtime/plugins/view/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ export async function setupDevToolsClient({
iframe.id = 'nuxt-devtools-iframe'
iframe.src = initialUrl
iframe.onload = async () => {
await waitForClientInjection()
client.syncClient()
try {
await waitForClientInjection()
client.syncClient()
}
catch (e) {
console.error('Nuxt DevTools client injection failed')
console.error(e)
}
}
}
catch (e) {
Expand All @@ -141,12 +147,13 @@ export async function setupDevToolsClient({
}

function waitForClientInjection(retry = 10, timeout = 200) {
let lastError: any
const test = () => {
try {
return !!iframe?.contentWindow?.__NUXT_DEVTOOLS_VIEW__
}
catch (e) {

lastError = e
}
return false
}
Expand All @@ -162,8 +169,7 @@ export async function setupDevToolsClient({
}
else if (retry-- <= 0) {
clearInterval(interval)
// eslint-disable-next-line prefer-promise-reject-errors
reject('Nuxt DevTools client injection failed')
reject(lastError)
}
}, timeout)
})
Expand Down

0 comments on commit de9baa3

Please sign in to comment.