oxynote/web/app/utils/html.ts
2026-08-03 18:40:10 +02:00

27 lines
486 B
TypeScript

export function waitForHtmlElementById(id: string, timeoutMs: number) {
if (typeof document === "undefined") {
return Promise.resolve(null)
}
return new Promise<HTMLElement | null>((resolve) => {
const start = performance.now()
const check = () => {
const el = document.getElementById(id)
if (el) {
resolve(el)
return
}
if (performance.now() - start >= timeoutMs) {
resolve(null)
return
}
requestAnimationFrame(check)
}
check()
})
}