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

Reduce dependency overhead #17

Open
ghost opened this issue May 24, 2020 · 4 comments
Open

Reduce dependency overhead #17

ghost opened this issue May 24, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented May 24, 2020

jsdom and user-agents bloat this package to 6.2 MB minified.
I suggest making the user agent user supplied and replacing jsdom with cheerio or something like this.

@sayem314
Copy link
Owner

JSDOM can't be replaced with Cheerio. The goal of JSDOM is to provide an identical DOM environment as what we see in the browser. And about user-agents, yes I might remove this in the future.

@sayem314 sayem314 added the enhancement New feature or request label May 24, 2020
@ghost
Copy link
Author

ghost commented May 24, 2020

Thanks for the answer.
Is jsdom actually used for anything but parsing the html?
I didn't see this when checking the code.

@sayem314
Copy link
Owner

It's used here both for retrieving form data and solving challenges from Cloudflare.

hooman/lib/core.js

Lines 11 to 33 in fd80462

// Emulate browser dom
const { document } = new JSDOM(html, { url, referrer: url }).window;
// Parse script to execute
let jschl_answer = document.getElementsByTagName('script')[0].textContent;
jschl_answer = jschl_answer.substring(jschl_answer.indexOf('var s'));
jschl_answer = jschl_answer.substring(0, jschl_answer.indexOf('f.submit'));
jschl_answer = jschl_answer.replace('location.', 'document.location.');
// Retrive answers from form to submit challenge
const body = [];
vm.runInNewContext(
`${jschl_answer}
// Retrive answers from form to submit challenge
const input = document.getElementsByTagName("input");
for (const i of input) {
body.push(i.name + "=" + encodeURIComponent(i.value));
}`,
{ document, body }
);
// Parse request information
const { method, action, enctype } = document.getElementById('challenge-form');

@Kikobeats
Copy link

@sayem314 can I suggest you use top-user-agents?

It's just a JSON of user agents, updated every time you fetch the package.

849 bytes of package 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants