// scripts/navigator-patch.cjs // // Workaround for Node 22 + @webex/internal-media-core. // // The bot framework transitively depends on `@webex/internal-media-core`, whose // pre-compiled CJS bundle does `commonjsGlobal.navigator = { ... }` at import time. // Node 22+ exposes `globalThis.navigator` as a non-writable property, so that // assignment throws: // // TypeError: Cannot set property navigator of # which has only a getter // // `--require` runs synchronously before any ESM resolution, which is the only // hook early enough to fix the descriptor before the framework loads. // // We make the property writable + configurable, preserving any existing value // so anything that reads from it later still works. 'use strict'; try { const desc = Object.getOwnPropertyDescriptor(globalThis, 'navigator'); if (desc && desc.writable !== true) { const current = 'value' in desc ? desc.value : (desc.get ? desc.get() : undefined); Object.defineProperty(globalThis, 'navigator', { value: current, writable: true, configurable: true, }); } } catch (err) { // If the patch can't apply, log loudly so the bot startup failure is at // least traceable; the framework import will then fail with the original error. // eslint-disable-next-line no-console console.warn('[navigator-patch] failed to make globalThis.navigator writable:', err && err.message); }