Skip to content

Commit 03b057d

Browse files
committed
wip
1 parent c96bef2 commit 03b057d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const globalThisPolyfill = `(function () {
2+
// polyfill for globalThis
3+
if (typeof globalThis === 'undefined') {
4+
if (typeof self !== 'undefined') {
5+
self.globalThis = self
6+
} else if (typeof window !== 'undefined') {
7+
window.globalThis = window
8+
} else if (typeof global !== 'undefined') {
9+
global.globalThis = global
10+
} else {
11+
throw new Error('Unable to locate global object')
12+
}
13+
}
14+
})()`
15+
16+
export const polyfills = [globalThisPolyfill].join('\n')

packages/signals/signals/src/core/processor/sandbox.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AnalyticsRuntimePublicApi } from '../../types'
55
import { replaceBaseUrl } from '../../lib/replace-base-url'
66
import { Signal } from '@segment/analytics-signals-runtime'
77
import { getWebRuntimeString } from '@segment/analytics-signals-runtime'
8+
import { polyfills } from './polyfills'
89

910
export type MethodName =
1011
| 'page'
@@ -211,9 +212,10 @@ export class Sandbox {
211212
}
212213
logger.debug('processing signal', { signal, scope, signals })
213214
const code = [
215+
polyfills,
214216
await this.settings.processSignal,
215217
getWebRuntimeString(),
216-
`const signals = new Signals(${JSON.stringify(signals)})`,
218+
`var signals = new Signals(${JSON.stringify(signals)})`,
217219
'try { processSignal(' +
218220
JSON.stringify(signal) +
219221
', { analytics, signals, SignalType, EventType, NavigationAction }); } catch(err) { console.error("Process signal failed.", err); }',

0 commit comments

Comments
 (0)