@npaw/forge-web 10.0.4 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -121,6 +121,70 @@ var NPAWForge = (() => {
121
121
  withoutNetworkCapture: () => withoutNetworkCapture
122
122
  });
123
123
 
124
+ // src/global.ts
125
+ function getGlobalObject() {
126
+ if (typeof globalThis !== "undefined") {
127
+ return globalThis;
128
+ }
129
+ if (typeof self !== "undefined") {
130
+ return self;
131
+ }
132
+ if (typeof window !== "undefined") {
133
+ return window;
134
+ }
135
+ throw new Error("no global object available");
136
+ }
137
+
138
+ // src/compat-bootstrap.ts
139
+ function installLegacyRuntimeShims(target) {
140
+ var _a;
141
+ let host;
142
+ try {
143
+ host = target != null ? target : getGlobalObject();
144
+ } catch (e2) {
145
+ return;
146
+ }
147
+ try {
148
+ if (typeof host.globalThis === "undefined") {
149
+ host.globalThis = host;
150
+ }
151
+ } catch (e2) {
152
+ }
153
+ try {
154
+ if (typeof host.queueMicrotask !== "function") {
155
+ host.queueMicrotask = function queueMicrotask2(callback) {
156
+ Promise.resolve().then(callback).catch((error) => {
157
+ setTimeout(() => {
158
+ throw error;
159
+ }, 0);
160
+ });
161
+ };
162
+ }
163
+ } catch (e2) {
164
+ }
165
+ try {
166
+ const arrayProto = (_a = host.Array) == null ? void 0 : _a.prototype;
167
+ if (arrayProto && typeof arrayProto.at !== "function") {
168
+ Object.defineProperty(arrayProto, "at", {
169
+ value: function at(index) {
170
+ const length = this.length >>> 0;
171
+ const relative = Math.trunc(Number(index) || 0);
172
+ const resolved = relative >= 0 ? relative : length + relative;
173
+ if (resolved < 0 || resolved >= length) {
174
+ return void 0;
175
+ }
176
+ return this[resolved];
177
+ },
178
+ writable: true,
179
+ configurable: true,
180
+ // Non-enumerable so host-app for..in loops over arrays stay safe.
181
+ enumerable: false
182
+ });
183
+ }
184
+ } catch (e2) {
185
+ }
186
+ }
187
+
124
188
  // src/types.ts
125
189
  var CAPTURE_PLAN_BITS = {
126
190
  NAVIGATION: 1 << 0,
@@ -1264,7 +1328,7 @@ var NPAWForge = (() => {
1264
1328
  if (environment.intersectionObserverFactory) {
1265
1329
  return environment.intersectionObserverFactory;
1266
1330
  }
1267
- const ctor = globalThis.IntersectionObserver;
1331
+ const ctor = getGlobalObject().IntersectionObserver;
1268
1332
  if (typeof ctor !== "function") {
1269
1333
  return void 0;
1270
1334
  }
@@ -1274,7 +1338,7 @@ var NPAWForge = (() => {
1274
1338
  if (environment.mutationObserverFactory) {
1275
1339
  return environment.mutationObserverFactory;
1276
1340
  }
1277
- const ctor = globalThis.MutationObserver;
1341
+ const ctor = getGlobalObject().MutationObserver;
1278
1342
  if (typeof ctor !== "function") {
1279
1343
  return void 0;
1280
1344
  }
@@ -3801,7 +3865,7 @@ var NPAWForge = (() => {
3801
3865
  }
3802
3866
  const generated = randomUuid();
3803
3867
  try {
3804
- (_a = globalThis.localStorage) == null ? void 0 : _a.setItem(DEVICE_UUID_STORAGE_KEY, generated);
3868
+ (_a = getGlobalObject().localStorage) == null ? void 0 : _a.setItem(DEVICE_UUID_STORAGE_KEY, generated);
3805
3869
  } catch (e2) {
3806
3870
  }
3807
3871
  return generated;
@@ -3809,14 +3873,14 @@ var NPAWForge = (() => {
3809
3873
  function readStoredUuid() {
3810
3874
  var _a;
3811
3875
  try {
3812
- const value = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(DEVICE_UUID_STORAGE_KEY);
3876
+ const value = (_a = getGlobalObject().localStorage) == null ? void 0 : _a.getItem(DEVICE_UUID_STORAGE_KEY);
3813
3877
  return value && value.trim().length > 0 ? value : void 0;
3814
3878
  } catch (e2) {
3815
3879
  return void 0;
3816
3880
  }
3817
3881
  }
3818
3882
  function randomUuid() {
3819
- const cryptoRef = globalThis.crypto;
3883
+ const cryptoRef = getGlobalObject().crypto;
3820
3884
  if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
3821
3885
  return cryptoRef.randomUUID();
3822
3886
  }
@@ -3950,11 +4014,11 @@ var NPAWForge = (() => {
3950
4014
  }
3951
4015
  function readBrowserDeviceInsightsEnvironment() {
3952
4016
  const environment = {};
3953
- const performanceRef = globalThis.performance;
4017
+ const performanceRef = getGlobalObject().performance;
3954
4018
  if (performanceRef && typeof performanceRef.memory === "object" && performanceRef.memory !== null) {
3955
4019
  environment.memory = () => performanceRef.memory;
3956
4020
  }
3957
- const navigatorRef = globalThis.navigator;
4021
+ const navigatorRef = getGlobalObject().navigator;
3958
4022
  if (navigatorRef && typeof navigatorRef.getBattery === "function") {
3959
4023
  environment.getBattery = () => navigatorRef.getBattery();
3960
4024
  }
@@ -4045,8 +4109,17 @@ var NPAWForge = (() => {
4045
4109
  function isPromiseLike(value) {
4046
4110
  return Boolean(value && typeof value.then === "function");
4047
4111
  }
4112
+ function fromEntries(entries) {
4113
+ const result = {};
4114
+ for (const entry of entries) {
4115
+ result[entry[0]] = entry[1];
4116
+ }
4117
+ return result;
4118
+ }
4048
4119
 
4049
4120
  // src/effects.ts
4121
+ var MAX_COMMAND_SUBSCRIPTIONS = 64;
4122
+ var COMMAND_NAME_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
4050
4123
  var BrowserEffectExecutor = class {
4051
4124
  constructor(options) {
4052
4125
  this.timers = /* @__PURE__ */ new Map();
@@ -4055,6 +4128,7 @@ var NPAWForge = (() => {
4055
4128
  this.diagnosticListeners = /* @__PURE__ */ new Set();
4056
4129
  this.logListeners = /* @__PURE__ */ new Set();
4057
4130
  this.capturePlanListeners = /* @__PURE__ */ new Set();
4131
+ this.commandListeners = /* @__PURE__ */ new Map();
4058
4132
  this.clock = options.clock;
4059
4133
  this.transport = options.transport;
4060
4134
  this.storage = options.storage;
@@ -4069,6 +4143,18 @@ var NPAWForge = (() => {
4069
4143
  if (options.onLog) {
4070
4144
  this.logListeners.add(options.onLog);
4071
4145
  }
4146
+ if (options.commandListeners) {
4147
+ for (const name of Object.keys(options.commandListeners)) {
4148
+ const listeners = options.commandListeners[name];
4149
+ if (!listeners) {
4150
+ continue;
4151
+ }
4152
+ const entries = Array.isArray(listeners) ? listeners : [listeners];
4153
+ for (const listener of entries) {
4154
+ this.registerCommandListener(name, listener);
4155
+ }
4156
+ }
4157
+ }
4072
4158
  }
4073
4159
  addEventListener(listener) {
4074
4160
  this.eventListeners.add(listener);
@@ -4089,6 +4175,51 @@ var NPAWForge = (() => {
4089
4175
  }
4090
4176
  return () => this.capturePlanListeners.delete(listener);
4091
4177
  }
4178
+ /**
4179
+ * Registers a remote command listener and re-sends the full subscription
4180
+ * set to the kernel. Every call is its own registration, even for a
4181
+ * function already registered under the name. Returns the unsubscribe
4182
+ * closure, which removes only that registration and re-sends the set
4183
+ * without the name once its last registration is gone.
4184
+ */
4185
+ addCommandListener(name, listener) {
4186
+ const registration = this.registerCommandListener(name, listener);
4187
+ if (!registration) {
4188
+ return () => void 0;
4189
+ }
4190
+ this.syncCommandSubscriptions();
4191
+ let active = true;
4192
+ return () => {
4193
+ if (!active) {
4194
+ return;
4195
+ }
4196
+ active = false;
4197
+ const registrations = this.commandListeners.get(registration.name);
4198
+ if (!registrations) {
4199
+ return;
4200
+ }
4201
+ const index = registrations.indexOf(registration);
4202
+ if (index >= 0) {
4203
+ registrations.splice(index, 1);
4204
+ }
4205
+ if (registrations.length === 0) {
4206
+ this.commandListeners.delete(registration.name);
4207
+ }
4208
+ this.syncCommandSubscriptions();
4209
+ };
4210
+ }
4211
+ /** The command names currently subscribed, sorted. */
4212
+ commandSubscriptions() {
4213
+ return Array.from(this.commandListeners.keys()).sort();
4214
+ }
4215
+ /** Sends the current subscription set (used by the bridge after `start`). */
4216
+ syncCommandSubscriptions() {
4217
+ this.submitCompletion({ type: "setCommandSubscriptions", names: this.commandSubscriptions() });
4218
+ }
4219
+ /** Drops every command listener without re-syncing (the runtime is gone). */
4220
+ clearCommandListeners() {
4221
+ this.commandListeners.clear();
4222
+ }
4092
4223
  execute(effects) {
4093
4224
  for (const effect of effects) {
4094
4225
  switch (effect.type) {
@@ -4125,6 +4256,9 @@ var NPAWForge = (() => {
4125
4256
  case "deviceSampleRequest":
4126
4257
  this.track(this.executeDeviceSampleRequest(effect.families));
4127
4258
  break;
4259
+ case "commandRequest":
4260
+ this.dispatchCommandRequest({ id: effect.id, name: effect.name, args: effect.args });
4261
+ break;
4128
4262
  default:
4129
4263
  break;
4130
4264
  }
@@ -4228,6 +4362,75 @@ var NPAWForge = (() => {
4228
4362
  }
4229
4363
  this.submitCompletion({ type: "recordDeviceSample", sample: compactDeviceSample(sample) });
4230
4364
  }
4365
+ /**
4366
+ * Validates and stores a listener. Blank or malformed names and the 65th
4367
+ * distinct name are refused with a diagnostic (the kernel would drop them
4368
+ * anyway) so a typo surfaces instead of silently never firing.
4369
+ */
4370
+ registerCommandListener(rawName, listener) {
4371
+ const name = typeof rawName === "string" ? rawName.trim() : "";
4372
+ if (!COMMAND_NAME_PATTERN.test(name)) {
4373
+ this.emitDiagnostic({
4374
+ code: "command_name_invalid",
4375
+ message: "command names are 1-64 characters of [A-Za-z0-9_.-]",
4376
+ recoverable: true,
4377
+ attributes: { name: String(rawName).slice(0, 64) }
4378
+ });
4379
+ return void 0;
4380
+ }
4381
+ let registrations = this.commandListeners.get(name);
4382
+ if (!registrations) {
4383
+ if (this.commandListeners.size >= MAX_COMMAND_SUBSCRIPTIONS) {
4384
+ this.emitDiagnostic({
4385
+ code: "command_subscriptions_limit",
4386
+ message: `at most ${MAX_COMMAND_SUBSCRIPTIONS} distinct command names can be subscribed`,
4387
+ recoverable: true,
4388
+ attributes: { name }
4389
+ });
4390
+ return void 0;
4391
+ }
4392
+ registrations = [];
4393
+ this.commandListeners.set(name, registrations);
4394
+ }
4395
+ const registration = { name, listener };
4396
+ registrations.push(registration);
4397
+ return registration;
4398
+ }
4399
+ /**
4400
+ * Hands a delivered command to every registration of its name, in
4401
+ * registration order and over a snapshot: a listener added or removed
4402
+ * while dispatching does not change who receives the in-flight command.
4403
+ * Each registration gets its own once-guarded `answer`; the kernel keeps
4404
+ * the first answer per command id. No registration (a race with an
4405
+ * unsubscribe) means no answer from here - the kernel auto-answers only
4406
+ * names nobody subscribed to.
4407
+ */
4408
+ dispatchCommandRequest(command) {
4409
+ const registrations = this.commandListeners.get(command.name);
4410
+ if (!registrations || registrations.length === 0) {
4411
+ return;
4412
+ }
4413
+ for (const { listener } of registrations.slice()) {
4414
+ let answered = false;
4415
+ const answer = (handled, details) => {
4416
+ if (answered) {
4417
+ return;
4418
+ }
4419
+ answered = true;
4420
+ this.submitCompletion({
4421
+ type: "commandAnswer",
4422
+ commandId: command.id,
4423
+ handled: Boolean(handled),
4424
+ details: normalizeDetails(details)
4425
+ });
4426
+ };
4427
+ try {
4428
+ listener({ id: command.id, name: command.name, args: command.args.slice() }, answer);
4429
+ } catch (error) {
4430
+ this.emitDiagnostic(diagnosticFromError(error, "command_listener_failed"));
4431
+ }
4432
+ }
4433
+ }
4231
4434
  scheduleTimer(timer) {
4232
4435
  this.cancelTimer(timer.id);
4233
4436
  const startedAtMs = this.clock.nowMs();
@@ -4305,6 +4508,20 @@ var NPAWForge = (() => {
4305
4508
  elapsedRealtimeMs: Math.round(base.elapsedRealtimeMs + actualDelayMs)
4306
4509
  };
4307
4510
  }
4511
+ function normalizeDetails(details) {
4512
+ const normalized = {};
4513
+ if (!details || typeof details !== "object") {
4514
+ return normalized;
4515
+ }
4516
+ for (const key of Object.keys(details)) {
4517
+ const value = details[key];
4518
+ if (value === void 0 || value === null) {
4519
+ continue;
4520
+ }
4521
+ normalized[key] = String(value);
4522
+ }
4523
+ return normalized;
4524
+ }
4308
4525
 
4309
4526
  // src/errors.ts
4310
4527
  var ForgeCreateError = class extends Error {
@@ -4344,13 +4561,14 @@ var NPAWForge = (() => {
4344
4561
  }
4345
4562
  function safeLocalStorage() {
4346
4563
  try {
4347
- if (typeof globalThis.localStorage === "undefined") {
4564
+ const host = getGlobalObject();
4565
+ if (typeof host.localStorage === "undefined") {
4348
4566
  return null;
4349
4567
  }
4350
4568
  const probe = "__npaw_forge_storage_probe__";
4351
- globalThis.localStorage.setItem(probe, "1");
4352
- globalThis.localStorage.removeItem(probe);
4353
- return globalThis.localStorage;
4569
+ host.localStorage.setItem(probe, "1");
4570
+ host.localStorage.removeItem(probe);
4571
+ return host.localStorage;
4354
4572
  } catch (e2) {
4355
4573
  return null;
4356
4574
  }
@@ -4359,10 +4577,11 @@ var NPAWForge = (() => {
4359
4577
  // src/transport.ts
4360
4578
  var BrowserForgeTransport = class {
4361
4579
  async send(request) {
4362
- if (typeof globalThis.fetch === "function") {
4580
+ const host = getGlobalObject();
4581
+ if (typeof host.fetch === "function") {
4363
4582
  return sendWithFetch(request);
4364
4583
  }
4365
- if (typeof globalThis.XMLHttpRequest === "function") {
4584
+ if (typeof host.XMLHttpRequest === "function") {
4366
4585
  return sendWithXhr(request);
4367
4586
  }
4368
4587
  throw new Error("fetch and XMLHttpRequest are unavailable");
@@ -4377,7 +4596,7 @@ var NPAWForge = (() => {
4377
4596
  if (body !== void 0) {
4378
4597
  init.body = body;
4379
4598
  }
4380
- const response = await withoutNetworkCapture(() => globalThis.fetch(requestUrl(request), init));
4599
+ const response = await withoutNetworkCapture(() => getGlobalObject().fetch(requestUrl(request), init));
4381
4600
  const headers = {};
4382
4601
  response.headers.forEach((value, key) => {
4383
4602
  headers[key] = value;
@@ -4430,8 +4649,9 @@ var NPAWForge = (() => {
4430
4649
  return base.toString();
4431
4650
  }
4432
4651
  function browserBaseUrl() {
4433
- if (typeof globalThis.location !== "undefined" && globalThis.location.href) {
4434
- return globalThis.location.href;
4652
+ const host = getGlobalObject();
4653
+ if (typeof host.location !== "undefined" && host.location.href) {
4654
+ return host.location.href;
4435
4655
  }
4436
4656
  return "https://localhost/";
4437
4657
  }
@@ -4519,6 +4739,9 @@ var NPAWForge = (() => {
4519
4739
  if (typeof ArrayBuffer === "undefined" || typeof Uint8Array === "undefined") {
4520
4740
  throw new Error("typed arrays are unavailable");
4521
4741
  }
4742
+ if (typeof TextEncoder === "undefined" || typeof TextDecoder === "undefined") {
4743
+ throw new Error("TextEncoder/TextDecoder are unavailable");
4744
+ }
4522
4745
  }
4523
4746
 
4524
4747
  // src/runtime.ts
@@ -4542,7 +4765,8 @@ var NPAWForge = (() => {
4542
4765
  onEvent: options.onEvent,
4543
4766
  onDiagnostic: options.onDiagnostic,
4544
4767
  onLog: options.onLog,
4545
- deviceSampleCollector: options.deviceSampleCollector
4768
+ deviceSampleCollector: options.deviceSampleCollector,
4769
+ commandListeners: options.commandListeners
4546
4770
  });
4547
4771
  }
4548
4772
  static async create(options) {
@@ -4557,7 +4781,20 @@ var NPAWForge = (() => {
4557
4781
  attributes: {}
4558
4782
  });
4559
4783
  }
4560
- const module = await normalizeWasmLoader(options.wasm).load();
4784
+ let module;
4785
+ try {
4786
+ module = await normalizeWasmLoader(options.wasm).load();
4787
+ } catch (error) {
4788
+ if (error instanceof ForgeCreateError) {
4789
+ throw error;
4790
+ }
4791
+ throw new ForgeCreateError({
4792
+ code: "wasm_instantiate_failed",
4793
+ message: describeWasmLoadError(error),
4794
+ recoverable: false,
4795
+ attributes: {}
4796
+ });
4797
+ }
4561
4798
  const response = module.forgeRuntimeCreate(runtimeConfig(options));
4562
4799
  if (!response.ok || !response.value) {
4563
4800
  throw new ForgeCreateError(boundaryDiagnostic(response.error));
@@ -4571,9 +4808,14 @@ var NPAWForge = (() => {
4571
4808
  onEvent: options.onEvent,
4572
4809
  onDiagnostic: options.onDiagnostic,
4573
4810
  onLog: options.onLog,
4574
- deviceSampleCollector: deviceSampleCollector(options)
4811
+ deviceSampleCollector: deviceSampleCollector(options),
4812
+ commandListeners: options.commandListeners
4575
4813
  });
4576
4814
  await bridge.process({ type: "start" });
4815
+ const subscriptions = bridge.commandSubscriptions();
4816
+ if (subscriptions.length > 0) {
4817
+ await bridge.process({ type: "setCommandSubscriptions", names: subscriptions });
4818
+ }
4577
4819
  return { bridge, module };
4578
4820
  }
4579
4821
  nowMs() {
@@ -4588,6 +4830,21 @@ var NPAWForge = (() => {
4588
4830
  onLog(listener) {
4589
4831
  return this.executor.addLogListener(listener);
4590
4832
  }
4833
+ /**
4834
+ * Subscribes to a remote command name. Adding or removing a listener
4835
+ * re-sends the full subscription set to the kernel. Once the runtime is
4836
+ * destroyed nothing is registered and the returned unsubscribe is inert.
4837
+ */
4838
+ onCommand(name, listener) {
4839
+ if (this.destroyed) {
4840
+ return () => void 0;
4841
+ }
4842
+ return this.executor.addCommandListener(name, listener);
4843
+ }
4844
+ /** The command names currently subscribed, sorted. */
4845
+ commandSubscriptions() {
4846
+ return this.executor.commandSubscriptions();
4847
+ }
4591
4848
  /**
4592
4849
  * Subscribes to kernel-computed capture plans. The latest plan already
4593
4850
  * observed by the effect executor is replayed to the new listener so
@@ -4625,6 +4882,7 @@ var NPAWForge = (() => {
4625
4882
  const batch = response.ok && response.value ? response.value : errorBatchFromBoundary(response.error);
4626
4883
  this.executor.execute(batch.effects);
4627
4884
  this.executor.cancelAll();
4885
+ this.executor.clearCommandListeners();
4628
4886
  await this.drainIdle();
4629
4887
  (_b = (_a = this.module).forgeRuntimeRelease) == null ? void 0 : _b.call(_a, this.handle);
4630
4888
  return batch;
@@ -4684,6 +4942,8 @@ var NPAWForge = (() => {
4684
4942
  } : command;
4685
4943
  case "recordDeviceSample":
4686
4944
  return command.sample.sampledAtMs === void 0 ? { ...command, sample: { ...command.sample, sampledAtMs: this.nowMs() } } : command;
4945
+ case "commandAnswer":
4946
+ return command.timemarkMs === void 0 ? { ...command, timemarkMs: this.nowMs() } : command;
4687
4947
  default:
4688
4948
  return command;
4689
4949
  }
@@ -4841,6 +5101,13 @@ var NPAWForge = (() => {
4841
5101
  const diagnostic = boundaryDiagnostic(error);
4842
5102
  return errorBatch(diagnostic.code, diagnostic.message);
4843
5103
  }
5104
+ function describeWasmLoadError(error) {
5105
+ if (error instanceof Error) {
5106
+ const name = error.name && error.name !== "Error" ? `${error.name}: ` : "";
5107
+ return `WASM kernel failed to load: ${name}${error.message}`;
5108
+ }
5109
+ return `WASM kernel failed to load: ${String(error)}`;
5110
+ }
4844
5111
  function boundaryDiagnostic(error) {
4845
5112
  if (!error) {
4846
5113
  return {
@@ -4931,7 +5198,7 @@ var NPAWForge = (() => {
4931
5198
  }
4932
5199
  };
4933
5200
  function readNavigatorConnection() {
4934
- const navigatorRef = globalThis.navigator;
5201
+ const navigatorRef = getGlobalObject().navigator;
4935
5202
  return navigatorRef == null ? void 0 : navigatorRef.connection;
4936
5203
  }
4937
5204
 
@@ -4996,7 +5263,7 @@ var NPAWForge = (() => {
4996
5263
  };
4997
5264
  }
4998
5265
  function readGeolocationEnvironment() {
4999
- const navigatorRef = globalThis.navigator;
5266
+ const navigatorRef = getGlobalObject().navigator;
5000
5267
  const geolocation = navigatorRef == null ? void 0 : navigatorRef.geolocation;
5001
5268
  const permissions = navigatorRef == null ? void 0 : navigatorRef.permissions;
5002
5269
  if (!geolocation || !(permissions == null ? void 0 : permissions.query)) {
@@ -5665,6 +5932,19 @@ var NPAWForge = (() => {
5665
5932
  onLog(listener) {
5666
5933
  return this.runtime.onLog(listener);
5667
5934
  }
5935
+ /**
5936
+ * Listens for a remote command by name. The backend delivers commands in the
5937
+ * responses of Forge's own analytics requests, so they arrive only while
5938
+ * events flow; a command nobody subscribed to is answered `handled=false`
5939
+ * by the kernel and never re-delivered - register listeners early (or
5940
+ * through `commandListeners` at create time). Every listener of the name
5941
+ * runs; call `answer(handled, details?)` at most once per listener, the
5942
+ * first answer per command id is reported as a `command-answer` event.
5943
+ * Returns the unsubscribe function.
5944
+ */
5945
+ onCommand(name, listener) {
5946
+ return this.runtime.onCommand(name, listener);
5947
+ }
5668
5948
  async startSession(params) {
5669
5949
  var _a, _b;
5670
5950
  const result = await this.session("sessionstart", params);
@@ -12186,7 +12466,7 @@ var NPAWForge = (() => {
12186
12466
  if (this.fetchAttempts >= maxFetchRetries) {
12187
12467
  return;
12188
12468
  }
12189
- const fetchFn = (_d = (_c = this.options) == null ? void 0 : _c.fetch) != null ? _d : globalThis.fetch;
12469
+ const fetchFn = (_d = (_c = this.options) == null ? void 0 : _c.fetch) != null ? _d : getGlobalObject().fetch;
12190
12470
  if (typeof fetchFn !== "function") {
12191
12471
  return;
12192
12472
  }
@@ -13718,7 +13998,7 @@ var NPAWForge = (() => {
13718
13998
  ERROR_VAST_XML_PARSING: "ERROR_VAST_XML_PARSING",
13719
13999
  ERROR_PARSE: "ERROR_PARSE"
13720
14000
  };
13721
- return Object.fromEntries(
14001
+ return fromEntries(
13722
14002
  Object.entries(fallback).map(([key, value]) => {
13723
14003
  var _a;
13724
14004
  return [key, (_a = stringValue(read(sdk, key))) != null ? _a : value];
@@ -13856,7 +14136,7 @@ var NPAWForge = (() => {
13856
14136
  StallStarted: "StallStarted",
13857
14137
  StallEnded: "StallEnded"
13858
14138
  };
13859
- return Object.fromEntries(
14139
+ return fromEntries(
13860
14140
  Object.entries(fallback).map(([key, value]) => {
13861
14141
  var _a;
13862
14142
  return [key, (_a = stringValue(read(events, key))) != null ? _a : value];
@@ -14217,7 +14497,7 @@ var NPAWForge = (() => {
14217
14497
  }
14218
14498
  }
14219
14499
  function cleanObject(value) {
14220
- return Object.fromEntries(
14500
+ return fromEntries(
14221
14501
  Object.entries(value).filter((entry) => entry[1] !== void 0)
14222
14502
  );
14223
14503
  }
@@ -14302,7 +14582,7 @@ var NPAWForge = (() => {
14302
14582
  return value == null ? void 0 : value.split("?")[0];
14303
14583
  }
14304
14584
  function globalRecord(name) {
14305
- return memberRecord(globalThis[name]);
14585
+ return memberRecord(getGlobalObject()[name]);
14306
14586
  }
14307
14587
  function realmOf(candidate) {
14308
14588
  var _a;
@@ -14329,6 +14609,7 @@ var NPAWForge = (() => {
14329
14609
  var adapters = NPAWForge.adapters;
14330
14610
 
14331
14611
  // src/script-entry.ts
14612
+ installLegacyRuntimeShims();
14332
14613
  var defaultInstancePromise2 = autoBootstrapFromCurrentScript();
14333
14614
  return __toCommonJS(script_entry_exports);
14334
14615
  })();