Skip to content

htmlcs: hide UMD loader globals during HTMLCS.js injection so HTMLCS_RUNNER reaches window (fixes #47)#52

Open
wittjeff wants to merge 1 commit into
jrpool:mainfrom
wittjeff:fix/htmlcs-umd-loader
Open

htmlcs: hide UMD loader globals during HTMLCS.js injection so HTMLCS_RUNNER reaches window (fixes #47)#52
wittjeff wants to merge 1 commit into
jrpool:mainfrom
wittjeff:fix/htmlcs-umd-loader

Conversation

@wittjeff

@wittjeff wittjeff commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #47.

What

tests/htmlcs.js now hides window.define / window.exports / window.module for the duration of the (synchronous) HTMLCS.js script insertion, then restores them.

Why

HTMLCS.js is a UMD bundle. On pages that expose an AMD loader (define.amd — Wix/Thunderbolt, RequireJS) or leaked CommonJS globals, the UMD wrapper registers HTMLCS as a module instead of taking its browser-global branch, so window.HTMLCS_RUNNER is never defined. window.HTMLCS_RUNNER.run(actStandard) then throws, and the whole act is reported prevented (ERROR executing HTMLCS_RUNNER in the page) — htmlcs silently returns zero results on a broad class of real-world sites. Full analysis in #47.

Hiding the loader globals makes the wrapper fall through to the browser-global branch; because the injected script executes synchronously, the globals are restored before any page code can observe their absence. The script-element injection is kept as-is, so CSP compatibility (no eval / new Function) is unchanged.

Verification

Live run against a hydrated Wix page (https://www.thesagemages.com), htmlcs act only, testaro 75.2.1:

prevented standard instances error
before true 0 ERROR executing HTMLCS_RUNNER in the page
after (this branch) false 61

The page's AMD loader works normally after the run. We have been running this change in production as a patch-package patch across daily multi-site scans since June with no htmlcs regressions.

…ool#47)

HTMLCS.js is a UMD bundle. On pages exposing an AMD loader (define.amd,
e.g. Wix/Thunderbolt, RequireJS) or leaked CommonJS globals, its wrapper
registers HTMLCS as a module and never attaches HTMLCS_RUNNER to window,
so window.HTMLCS_RUNNER.run() throws and the whole act is reported
prevented ("ERROR executing HTMLCS_RUNNER in the page").

Hide window.define/exports/module for the duration of the synchronous
script insertion so the wrapper falls through to its browser-global
branch, then restore them. Keeps the script-element injection (CSP-safe;
no eval/new Function).

Verified against a live Wix page (https://www.thesagemages.com):
before = prevented, 0 instances; after = 61 standard instances, AMD
loader intact afterward.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

htmlcs: HTMLCS_RUNNER undefined on pages with an AMD loader (define.amd) — UMD bundle misroutes, aborts the tool

2 participants