diff --git a/packages/taro-runtime/src/bom/window.ts b/packages/taro-runtime/src/bom/window.ts index 71a493e47c6c..a8ebf2908c0b 100644 --- a/packages/taro-runtime/src/bom/window.ts +++ b/packages/taro-runtime/src/bom/window.ts @@ -9,10 +9,21 @@ export const window = isBrowser ? win : { document } +if (!isBrowser) { + const globalProperties = [ + ...Object.getOwnPropertyNames(global || win), + ...Object.getOwnPropertySymbols(global || win) + ] + + globalProperties.forEach(property => { + if (!Object.prototype.hasOwnProperty.call(window, property)) { + window[property] = global[property] + } + }) +} + if (process.env.TARO_ENV !== 'h5') { (window as any).requestAnimationFrame = raf; (window as any).cancelAnimationFrame = caf; - (window as any).Date = Date; - (window as any).setTimeout = setTimeout; (window as any).getComputedStyle = getComputedStyle }