[GH-ISSUE #460] [Issue]: extension loader leaves this undefined inside module wrapper, breaking classic-script-style extensions #203

Closed
opened 2026-10-20 17:26:13 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/460

Summary

The v1.5.8 extension loader in CustomThemeInjector.tsx wraps user JS inside a function and invokes it as executeExtension(marinara) (no explicit this binding). Because the wrapper is loaded as an ES module via import(blob:URL), the function inherits strict mode, and this is undefined inside extension code. This silently breaks classic-script-style extensions that rely on this === window for top-level global assignment patterns like this.foo = bar.

Expected behavior

Inside extension code, this should be bound to the global object (matching v1.5.7's new Function(\"marinara\", ext.js) semantics, where this was the global object when invoked without an explicit binding). Extensions written in classic-script style should continue to work after the v1.5.8 loader change.

Actual behavior

this is undefined at the top level of extension code. Top-level this.foo = bar throws TypeError: Cannot set properties of undefined (setting 'foo'). The extension fails silently — the only trace is the per-extension console.error(\"[Extension:...] Failed to execute:\", e) line.

Steps to reproduce

  1. Install Marinara Engine v1.5.8.

  2. Create a .js extension file containing only:

    this.SOMETHING = "yes";
    console.log(\"this is:\", this === window ? \"window\" : typeof this);
    
  3. Settings → Extensions → Import the file → refresh.

  4. Open DevTools → Console.

Observed: Uncaught TypeError: Cannot set properties of undefined (setting 'SOMETHING').
Expected: this is: window.

Environment

  • Marinara Engine version: 1.5.8
  • Install type: Docker (via EasyPanel autoDeploy from a Pasta-Devs fork)
  • OS + version: Container Linux on Linode VPS, browser-side: Windows 11 / Chromium-based
  • Browser: latest Chromium

Logs, screenshots, or video

Verified end-to-end on a local fork with a candidate fix applied. Test extension prints this === window (green pass banner) after the fix, vs. the TypeError above on stock v1.5.8.

Additional context

Discovered while reviewing #431 (kolacheee's alternative server-side-loaded <script src> approach, which was closed in favor of the v1.5.8 blob-URL loader). The architectural choice to keep the loader client-only is fine; the strict-mode this issue is a small follow-up to make the v1.5.8 loader compatible with the same range of extension styles the v1.5.7 loader supported.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (May 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/460 ## Summary The v1.5.8 extension loader in `CustomThemeInjector.tsx` wraps user JS inside a function and invokes it as `executeExtension(marinara)` (no explicit `this` binding). Because the wrapper is loaded as an ES module via `import(blob:URL)`, the function inherits strict mode, and `this` is `undefined` inside extension code. This silently breaks classic-script-style extensions that rely on `this === window` for top-level global assignment patterns like `this.foo = bar`. ## Expected behavior Inside extension code, `this` should be bound to the global object (matching v1.5.7's `new Function(\"marinara\", ext.js)` semantics, where `this` was the global object when invoked without an explicit binding). Extensions written in classic-script style should continue to work after the v1.5.8 loader change. ## Actual behavior `this` is `undefined` at the top level of extension code. Top-level `this.foo = bar` throws `TypeError: Cannot set properties of undefined (setting 'foo')`. The extension fails silently — the only trace is the per-extension `console.error(\"[Extension:...] Failed to execute:\", e)` line. ## Steps to reproduce 1. Install Marinara Engine v1.5.8. 2. Create a `.js` extension file containing only: ```js this.SOMETHING = "yes"; console.log(\"this is:\", this === window ? \"window\" : typeof this); ``` 3. Settings → Extensions → Import the file → refresh. 4. Open DevTools → Console. **Observed:** `Uncaught TypeError: Cannot set properties of undefined (setting 'SOMETHING')`. **Expected:** `this is: window`. ## Environment - Marinara Engine version: 1.5.8 - Install type: Docker (via EasyPanel autoDeploy from a Pasta-Devs fork) - OS + version: Container Linux on Linode VPS, browser-side: Windows 11 / Chromium-based - Browser: latest Chromium ## Logs, screenshots, or video Verified end-to-end on a local fork with a candidate fix applied. Test extension prints `this === window` (green pass banner) after the fix, vs. the `TypeError` above on stock v1.5.8. ## Additional context Discovered while reviewing #431 (kolacheee's alternative server-side-loaded `<script src>` approach, which was closed in favor of the v1.5.8 blob-URL loader). The architectural choice to keep the loader client-only is fine; the strict-mode `this` issue is a small follow-up to make the v1.5.8 loader compatible with the same range of extension styles the v1.5.7 loader supported. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:26:13 +07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#203
No description provided.