Skip to content
This repository was archived by the owner on Nov 16, 2025. It is now read-only.
This repository was archived by the owner on Nov 16, 2025. It is now read-only.

Integrate jsdom feature flags #38

@ghost

Description

This not an issue for your project. I just wanted to pass along a comment I just posted on the jsdom github site:
...
I reported on this issue, see #290. Inspired by this post (#328), I also tried the html5 parser. Code snippet:

                request(url, function (error, response, body) {
                    if (error) {
                        onError(message, error, socket);
                    } else {
                        var window = jsdom.jsdom(null, null, { parser : html5 }).createWindow();
                        var parser = new html5.Parser({ document: window.document });
                        parser.parse(body);
                        jsdom.jQueryify(window, jQueryLib, function(window, jquery) {
                            var $ = window.$;
                            // Do work...
                        });
                    }
                });

This pattern can be found on the htlm5 github site. While I was able to pass in 'features' options (as detailed above), the jsdom.jQueryify function appears to overwrite the feature's settings. See jsdom.js (lines 122-4):

122 window.document.implementation.addFeature('FetchExternalResources', ['script']);
123 window.document.implementation.addFeature('ProcessExternalResources', ['script']);
124 window.document.implementation.addFeature('MutationEvents', ["1.0"]);

Naturally, I wanted to set these to false to avoid script processing. My only option was to edited the code, setting all 3 features to false. It would be nice if the global defaultDocumentFeatures function worked as expected or the jQueryify function signature provided for options/features.
...

So using the html5 parser allows me to circumvent the jsdom 'hierarchy request' error. But the integration between html5 and jsdom does not allow me to disable target features. Unless, I'm missing something.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions