Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

v4.0.0 #198

Merged
merged 15 commits into from Apr 22, 2019
Merged

v4.0.0 #198

merged 15 commits into from Apr 22, 2019

Conversation

ghost
Copy link

@ghost ghost commented Apr 15, 2019

Supersedes #196

  • Add tests
  • Adds lib/browsers.json - contains UA and exact header information
  • Adds lib/headers.js - loads a random UA from lib/browsers.json
  • Replaces all occurrences of var with either const or let
  • Tiny regex modification to slightly improve document.getElementById
  • Adds optional support for Brotli and headers are adapted depending on whether or not it's available
  • Adds lib/brotli.js for the optional support (node's or user installed version)
  • Makes both request and brotli peer dependencies which must be installed by the user.
  • Moves sandbox(vm) related code to lib/sandbox.js and increases testability
  • Adds support for solving reCAPTCHA(v2)
  • Renames functions e.g. processsResponseBody -> onRequestComplete
  • Moves request options validation to it's own function: validateRequest

If a user attempts to run cloudscraper without first installing request, they will receive the following error message:

###
### The "request" library is not installed automatically anymore.
### But is a dependency of "request-promise".
### Please install it with:
### npm install request --save
###

{ Error: Cannot find module 'request'
<snipped>

The error message is automatically produced by request-promise.
Closes #147
Closes #62

@ghost ghost mentioned this pull request Apr 15, 2019
@ghost ghost mentioned this pull request Apr 15, 2019
@codemanki
Copy link
Owner

Just got back from a short vacation and so many things happened here O.o I'm gonna review all the changes asap

@ghost
Copy link
Author

ghost commented Apr 16, 2019

@codemanki You might want to hold off until I push these tests

@ghost
Copy link
Author

ghost commented Apr 16, 2019

The code coverage is sane again but not quite 100%
I'll cover the rest of it very soon. Feel free to review now.

index.js Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Apr 18, 2019

Hey, I've changed my mind. I'm not going to add any extra additional tests for the time being but the PR does LGTM. I can address any issues if you see any.

lib/sandbox.js Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Apr 18, 2019

Also to clarify, Brotli is a completely optional dependency but if anybody intends on having bulletproof headers, they should install it.

@ghost
Copy link
Author

ghost commented Apr 18, 2019

@VeNoMouS you might want to review that last comment I made.

@ghost
Copy link
Author

ghost commented Apr 18, 2019

One last thing to mention is that there is some percentage of the user base that is facing issues that this PR resolves by beating Cloudflare's updated BIC checks.

@codemanki
Copy link
Owner

There are no breaking changes, right?

@ghost
Copy link
Author

ghost commented Apr 21, 2019

No breaking changes other than what I noted above... request is now a peer dependency which the user must install themselves.

@ghost
Copy link
Author

ghost commented Apr 21, 2019

TBH, it's sitting here when it works better than the master branch. I consider the current release to be broken.

@codemanki
Copy link
Owner

codemanki commented Apr 21, 2019 via email

@ghost
Copy link
Author

ghost commented Apr 21, 2019

@codemanki Before you do, check the resolved messages, they're not all resolved. I'm too busy to fix thoses but even without them being fixed...Still better than current release.

@codemanki
Copy link
Owner

@pro-src could you please change the target branch from master to https://github.com/codemanki/cloudscraper/tree/4.0.0 ?

@ghost ghost changed the base branch from master to 4.0.0 April 21, 2019 13:23
@ghost
Copy link
Author

ghost commented Apr 21, 2019

Done.

index.js Show resolved Hide resolved
}

stringBody = body.toString('utf8');

try {
validate(options, response, stringBody);
} catch (error) {
if (error instanceof CaptchaError && typeof options.onCaptcha === 'function') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to document this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a few examples as a part of that documentation. See the relevant issue for examples.

@codemanki
Copy link
Owner

@pro-src i will then merge this PR, will add my changes to the branch and will create a new PR. Otherwise I can't add my changes to your branch

@codemanki
Copy link
Owner

@ghost
Copy link
Author

ghost commented Apr 21, 2019

AFAIK you should be able to change the target branch back to master should you need to and change the title, etc. etc. 😉

@codemanki
Copy link
Owner

@pro-src is it safe? :D Feels like disarming a bomb
Screen Shot 2019-04-21 at 16 02 35

@ghost
Copy link
Author

ghost commented Apr 21, 2019

Yes, it is safe. 💣

@codemanki codemanki changed the base branch from 4.0.0 to master April 21, 2019 14:12
@codemanki
Copy link
Owner

I guess it is ready to be released. @pro-src do you want to take a quick look?

@TravisBuddy
Copy link

TravisBuddy commented Apr 22, 2019

Travis tests have failed

Hey @pro-src,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

Node.js: node

View build log

npm test
> cloudscraper@4.0.0 test /home/travis/build/codemanki/cloudscraper
> npm run lint && nyc --reporter=html --reporter=text mocha


> cloudscraper@4.0.0 lint /home/travis/build/codemanki/cloudscraper
> eslint --ext .json --ext .js .


/home/travis/build/codemanki/cloudscraper/examples/solve-recaptcha.js
   3:24   error  Missing space before function parentheses      space-before-function-paren
   4:3    error  Expected space or tab after '//' in comment    spaced-comment
  18:1    error  Expected catch() or return                     promise/catch-or-return
  18:49   error  Strings must use singlequote                   quotes
  18:103  error  Newline required at end of file but not found  eol-last
  18:103  error  Missing semicolon                              semi

✖ 6 problems (6 errors, 0 warnings)
  5 errors and 0 warnings potentially fixable with the `--fix` option.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cloudscraper@4.0.0 lint: `eslint --ext .json --ext .js .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cloudscraper@4.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2019-04-22T15_16_02_639Z-debug.log
npm ERR! Test failed.  See above for more details.

Node.js: 6

View build log

npm test
> cloudscraper@4.0.0 test /home/travis/build/codemanki/cloudscraper
> npm run lint && nyc --reporter=html --reporter=text mocha


> cloudscraper@4.0.0 lint /home/travis/build/codemanki/cloudscraper
> eslint --ext .json --ext .js .


/home/travis/build/codemanki/cloudscraper/examples/solve-recaptcha.js
   3:24   error  Missing space before function parentheses      space-before-function-paren
   4:3    error  Expected space or tab after '//' in comment    spaced-comment
  18:1    error  Expected catch() or return                     promise/catch-or-return
  18:49   error  Strings must use singlequote                   quotes
  18:103  error  Newline required at end of file but not found  eol-last
  18:103  error  Missing semicolon                              semi

✖ 6 problems (6 errors, 0 warnings)
  5 errors and 0 warnings potentially fixable with the `--fix` option.


npm ERR! Linux 4.4.0-101-generic
npm ERR! argv "/home/travis/.nvm/versions/node/v6.17.1/bin/node" "/home/travis/.nvm/versions/node/v6.17.1/bin/npm" "run" "lint"
npm ERR! node v6.17.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! cloudscraper@4.0.0 lint: `eslint --ext .json --ext .js .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cloudscraper@4.0.0 lint script 'eslint --ext .json --ext .js .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cloudscraper package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     eslint --ext .json --ext .js .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cloudscraper
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cloudscraper
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/travis/build/codemanki/cloudscraper/npm-debug.log
npm ERR! Test failed.  See above for more details.
TravisBuddy Request Identifier: b9d627a0-6511-11e9-a049-ff6f6c17598f

@ghost
Copy link
Author

ghost commented Apr 22, 2019

Probably should make a dummy solveCaptcha function so the linter doesn't complain or you could just modify that NPM script to exclude the examples directory.

I usually do the following before committing: npm run lint -- --fix

LGTM 👍

@codemanki
Copy link
Owner

Here we go... Thank you @pro-src for this PR :)

@codemanki codemanki merged commit 79760a7 into codemanki:master Apr 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove request module dependency in v4 Add support for recaptcha
3 participants