Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate jsdom feature flags #38

Open
ghost opened this issue Oct 12, 2011 · 3 comments
Open

Integrate jsdom feature flags #38

ghost opened this issue Oct 12, 2011 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 12, 2011

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.

@aredridel
Copy link
Owner

Oh fun! I wasn't aware of @tmpvar adding those. I'll integrate those, unless you have ideas as to how it should work!

@ghost
Copy link
Author

ghost commented Oct 13, 2011

Given the above use case, the jsdom.jQueryify function should (1) provide an options parameter or (2) honor jsdom.jsdom options and/or global options. Doesn't that sound about right?

** Options to include features.

@aredridel
Copy link
Owner

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant