fix: prevent $tw.wiki undefined error

fixes #602
This commit is contained in:
linonetwo 2024-11-25 14:33:23 +08:00
parent 3e51aecd69
commit ed7a2ba7cc

View file

@ -94,7 +94,7 @@ async function executeTWJavaScriptWhenIdle<T>(script: string, options?: { onlyWh
(async () => await new Promise((resolve, reject) => {
const handler = () => {
requestIdleCallback(() => {
if (typeof $tw !== 'undefined') {
if (typeof $tw?.rootWidget !== 'undefined' && typeof $tw?.wiki !== 'undefined') {
try {
const result = (() => {
${script}