fix(app): add error handling to PdfViewer renderPage and VideoPlayer initHls
Prevents unhandled promise rejections from async watchers and lifecycle hooks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9b3fd5d973
commit
f84e68ad06
@@ -124,20 +124,24 @@ async function renderPage() {
|
||||
const canvas = canvasRef.value
|
||||
if (!doc || !canvas) return
|
||||
|
||||
const page = await doc.getPage(currentPage.value)
|
||||
const viewport = page.getViewport({ scale: scale.value })
|
||||
try {
|
||||
const page = await doc.getPage(currentPage.value)
|
||||
const viewport = page.getViewport({ scale: scale.value })
|
||||
|
||||
canvas.height = viewport.height
|
||||
canvas.width = viewport.width
|
||||
canvas.height = viewport.height
|
||||
canvas.width = viewport.width
|
||||
|
||||
const ctx = canvas.getContext('2d')
|
||||
if (!ctx) return
|
||||
const ctx = canvas.getContext('2d')
|
||||
if (!ctx) return
|
||||
|
||||
await page.render({
|
||||
canvasContext: ctx,
|
||||
canvas: canvas,
|
||||
viewport,
|
||||
}).promise
|
||||
await page.render({
|
||||
canvasContext: ctx,
|
||||
canvas: canvas,
|
||||
viewport,
|
||||
}).promise
|
||||
} catch (e) {
|
||||
error.value = `Failed to render page: ${e instanceof Error ? e.message : 'Unknown error'}`
|
||||
}
|
||||
}
|
||||
|
||||
function goToPage(page: number) {
|
||||
|
||||
@@ -58,24 +58,30 @@ const isHls = computed(() =>
|
||||
type HlsInstance = import('hls.js').default
|
||||
const hls = shallowRef<HlsInstance | null>(null)
|
||||
|
||||
const hlsError = ref('')
|
||||
|
||||
async function initHls() {
|
||||
if (!isHls.value || !videoRef.value || youtubeId.value) return
|
||||
|
||||
const HlsModule = await import('hls.js')
|
||||
const Hls = HlsModule.default
|
||||
try {
|
||||
const HlsModule = await import('hls.js')
|
||||
const Hls = HlsModule.default
|
||||
|
||||
if (!Hls.isSupported()) {
|
||||
// Try native HLS support (Safari)
|
||||
if (videoRef.value.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
videoRef.value.src = props.url
|
||||
if (!Hls.isSupported()) {
|
||||
// Try native HLS support (Safari)
|
||||
if (videoRef.value.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
videoRef.value.src = props.url
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const instance = new Hls()
|
||||
instance.loadSource(props.url)
|
||||
instance.attachMedia(videoRef.value)
|
||||
hls.value = instance
|
||||
const instance = new Hls()
|
||||
instance.loadSource(props.url)
|
||||
instance.attachMedia(videoRef.value)
|
||||
hls.value = instance
|
||||
} catch (e) {
|
||||
hlsError.value = `Failed to initialize video: ${e instanceof Error ? e.message : 'Unknown error'}`
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user