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

Custom ResourceLoader support #36

Open
fstanis opened this issue Nov 4, 2019 · 2 comments · May be fixed by #37
Open

Custom ResourceLoader support #36

fstanis opened this issue Nov 4, 2019 · 2 comments · May be fixed by #37

Comments

@fstanis
Copy link

fstanis commented Nov 4, 2019

JSDom supports a custom resource loader, e.g:

class CustomResourceLoader extends jsdom.ResourceLoader {
  fetch(url, options) {
    console.log(`Loading ${url}...`);
    return super.fetch(url, options);
  }
}

const dom = new JSDOM(``, { resources: new CustomResourceLoader() });

However, window (and browser-env) doesn't allow this because it overrides the resources field:

window/src/index.js

Lines 8 to 12 in 82c7830

const resources = new ResourceLoader({
proxy,
strictSSL,
userAgent
});

Any chance this could be changed so that a custom loader is allowed?

@lukechilds
Copy link
Owner

Sure, I'd happily accept a PR for this as long as it doesn't break existing behaviour.

@fstanis fstanis linked a pull request Nov 6, 2019 that will close this issue
@fstanis
Copy link
Author

fstanis commented Nov 6, 2019

Sure, #37 does this.

It feels a bit clunky, I think the best option would be to just forward the whole jsdomConfig, i.e.

module.exports = class Window {
	constructor(jsdomConfig = {}) {
		return (new JSDOM('', jsdomConfig)).window;
	}
};

But I'm assuming there's some context I'm missing and also this would break backwards compatibility.

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 a pull request may close this issue.

2 participants