Currently its not possible to call getInternalVMContext in beforeParse
Author: KnisterPeterCreated Feb 24, 2021Updated Sep 17, 2026
Basic info:
- Node.js version: any
- jsdom version: latest (16.x.x)
Minimal reproduction case
const { JSDOM } = require("jsdom");
const { Script } = require("script");
const script = new Script('...');
const dom = new JSDOM(`
<html></html>
`, {
beforeParse(window) {
// it failes here, because `dom` isn't accessiable.
// on the given `window` the context cannot be fetched from (I think thats caused by the _globalProxy thing)
script.runInContext(dom.getInternalVMContext());
}
});
How does similar code behave in browsers?
Not applicable, because there is no similar API. The reason to setup this, is to create multiple instances of JSDOM and share precompiled scripts between them. These need to be setup and made available before the parsing starts.
Ideas
Would it be possible to add the context as a second paramter to the beforeParse function?
Source: jsdom/jsdom