{"record":{"id":"59f0c838cddb2e19","repo":"eythaann/Seelen-UI","slug":"the-library-is-being-used-on-a-non-seelen-ui-envir","errorCode":null,"errorMessage":"The library is being used on a non Seelen UI environment","messagePattern":"The library is being used on a non Seelen UI environment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libs/core/src/state/widget/mod.ts","lineNumber":44,"sourceCode":"interface WidgetInternalState {\n  hwnd: number;\n  initialized: boolean;\n  ready: boolean;\n  firstFocus: boolean;\n}\n\n/**\n * Represents the widget instance running in the current webview\n */\nexport class Widget {\n  /**\n   * Alternative accesor for the current running widget.\\\n   * Will throw if the library is being used on a non Seelen UI environment\n   */\n  static getCurrent(): Widget {\n    const scope = globalThis as ExtendedGlobalThis;\n    if (!scope.__SLU_WIDGET) {\n      throw new Error(\"The library is being used on a non Seelen UI environment\");\n    }\n    return (\n      scope.__SLU_WIDGET_INSTANCE || (scope.__SLU_WIDGET_INSTANCE = new Widget(scope.__SLU_WIDGET))\n    );\n  }\n\n  /** The current running widget */\n  static get self(): Widget {\n    return Widget.getCurrent();\n  }\n\n  /** widget id */\n  public readonly id: WidgetId;\n  /** widget definition */\n  public readonly def: IWidget;\n  /** decoded widget instance information */\n  public readonly decoded: WidgetInformation;\n  /** current webview where the widget is running */","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/libs/core/src/state/widget/mod.ts#L26-L62","documentation":"Widget.getCurrent() is the static accessor for the widget instance running inside a Seelen UI webview. The library reads the global __SLU_WIDGET injection that Seelen UI sets on every widget webview before running its code; if that global is missing, the code is not running inside a Seelen UI widget environment, so the library refuses to continue rather than returning a broken Widget instance.","triggerScenarios":"Calling Widget.getCurrent() (directly or via the Widget.ready() flow) in a plain browser tab, a normal webview not spawned by Seelen UI, a unit-test environment (jsdom/node) without the global injected, or a webview whose preload/injection script failed to define globalThis.__SLU_WIDGET before library code ran.","commonSituations":"Running widget frontend code standalone with a dev server; executing widget modules in Vitest/Jest tests; loading @seelen-ui/lib from a random website; opening the widget's dist/index.html directly in a browser; injection-order regression where module top-level code calls getCurrent() before the global is injected.","solutions":["Run the code inside a Seelen UI webview (load the widget through Seelen UI, not a plain browser).","For tests or standalone dev, stub the environment before importing the library: set (globalThis as any).__SLU_WIDGET = { id: 'test', ... } or mock @seelen-ui/lib.","Guard the call site: check (globalThis as any).__SLU_WIDGET before calling getCurrent() and take a no-op path outside Seelen UI.","If inside Seelen UI and still failing, update @seelen-ui/lib and Seelen UI to matching versions so the injection global matches."],"exampleFix":"// before: const widget = Widget.getCurrent(); // throws in plain browser/tests\n// after: if (!(globalThis as any).__SLU_WIDGET) { return null; } const widget = Widget.getCurrent();","handlingStrategy":"validation","validationCode":"function isSeelenUiEnv(): boolean { return Boolean((globalThis as any).__SLU_WIDGET); } // call before getCurrent(); if false, skip widget setup or inject a test stub","typeGuard":"function isInSeelenUi(): boolean { return typeof (globalThis as any).__SLU_WIDGET !== 'undefined' && (globalThis as any).__SLU_WIDGET !== null; }","tryCatchPattern":"let widget: Widget | null = null; try { widget = Widget.getCurrent(); } catch (e) { if (e instanceof Error && e.message.includes('non Seelen UI environment')) { widget = null; } else { throw e; } }","preventionTips":["Only run widget code inside Seelen UI webviews.","Stub __SLU_WIDGET in test/dev setups before importing @seelen-ui/lib.","Never call Widget.getCurrent() from module top-level in shared code that also runs outside widgets.","Keep @seelen-ui/lib and Seelen UI versions in sync."],"tags":["environment","runtime","initialization"],"backgroundTag":"missing-runtime-environment","analyzedSha":"dee4aaa94066c5d0888ab25554864862fc47be15","analyzedAt":"2026-09-03T10:20:37.842Z","contentChangedAt":"2026-09-03T10:20:37.842Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}