|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { DocksContext } from '@vitejs/devtools-kit/client' |
| 3 | +import { CLIENT_CONTEXT_KEY, getDevToolsRpcClient } from '@vitejs/devtools-kit/client' |
| 4 | +import { createDocksContext, DockStandalone } from '@vitejs/devtools/client/webcomponents' |
| 5 | +import { nextTick, ref, useTemplateRef, watch } from 'vue' |
| 6 | +import { getInspectedWindowMetadata } from './inspected-window' |
| 7 | +
|
| 8 | +const context = ref<DocksContext | null>(null) |
| 9 | +const error = ref<string | null>(null) |
| 10 | +const dockRoot = useTemplateRef<HTMLElement>('dockRoot') |
| 11 | +
|
| 12 | +watch([dockRoot, context], ([root, docksContext]) => { |
| 13 | + if (!root || !docksContext || root.childElementCount) |
| 14 | + return |
| 15 | +
|
| 16 | + root.appendChild(new DockStandalone({ context: docksContext })) |
| 17 | +}) |
| 18 | +
|
| 19 | +try { |
| 20 | + const meta = await getInspectedWindowMetadata() |
| 21 | +
|
| 22 | + const rpc = await getDevToolsRpcClient({ |
| 23 | + authToken: meta.authToken, |
| 24 | + connectionMeta: meta.connectionMeta, |
| 25 | + wsOptions: { |
| 26 | + url: meta.wsUrl, |
| 27 | + }, |
| 28 | + }) |
| 29 | +
|
| 30 | + context.value = await createDocksContext('standalone', rpc) |
| 31 | + ;(globalThis as any)[CLIENT_CONTEXT_KEY] = context.value |
| 32 | + await nextTick() |
| 33 | +} |
| 34 | +catch (err) { |
| 35 | + error.value = err instanceof Error ? err.message : String(err) |
| 36 | +} |
| 37 | +</script> |
| 38 | + |
| 39 | +<template> |
| 40 | + <div v-if="context" ref="dockRoot" class="h-screen w-screen" /> |
| 41 | + <div v-else class="h-screen w-screen flex items-center justify-center bg-[#0b1120] px-6 text-white/80"> |
| 42 | + <div class="max-w-lg rounded-xl border border-white/10 bg-white/5 px-5 py-4 text-sm leading-6 shadow-xl"> |
| 43 | + <p class="m0 text-base font-semibold text-white"> |
| 44 | + Vite DevTools panel unavailable |
| 45 | + </p> |
| 46 | + <p class="mb0 mt2"> |
| 47 | + {{ error || 'Connecting to the inspected page...' }} |
| 48 | + </p> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | +</template> |
0 commit comments