fix(platform[web worker]): improve globalThis variable retrieval for browser environment (#11495)

This commit is contained in:
白墨 2025-08-15 04:12:20 +08:00 committed by GitHub
parent 6e9f20d4d9
commit ec26eae824
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,10 +20,12 @@ export class PlatformTools {
static getGlobalVariable(): any {
if (typeof window !== "undefined") {
return window
} else {
// NativeScript uses global, not window
return global
}
if (typeof globalThis !== "undefined") {
return globalThis
}
// NativeScript uses global, not window
return global
}
/**
@ -162,6 +164,9 @@ declare var window: Window;
if (typeof window !== "undefined") {
window.Buffer = Buffer;
}
if (typeof globalThis !== "undefined") {
globalThis.Buffer = Buffer;
}
// NativeScript uses global, not window
if (typeof global !== "undefined" && typeof require !== "undefined") {
global.Buffer = require("buffer/").Buffer;