Skip to content

Commit fd80462

Browse files
committed
support electron (fix #16)
1 parent 72c096b commit fd80462

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

lib/core.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const { JSDOM } = require('jsdom');
3-
const { NodeVM } = require('vm2');
3+
const vm = require('vm');
44
const delay = require('./delay');
55

66
// Solve challange with this function
@@ -19,13 +19,15 @@ const solve = async (url, html) => {
1919

2020
// Retrive answers from form to submit challenge
2121
const body = [];
22-
const vm = new NodeVM({ sandbox: { document, body } });
23-
await vm.run(`${jschl_answer}
22+
vm.runInNewContext(
23+
`${jschl_answer}
2424
// Retrive answers from form to submit challenge
2525
const input = document.getElementsByTagName("input");
2626
for (const i of input) {
2727
body.push(i.name + "=" + encodeURIComponent(i.value));
28-
}`);
28+
}`,
29+
{ document, body }
30+
);
2931

3032
// Parse request information
3133
const { method, action, enctype } = document.getElementById('challenge-form');

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
"dependencies": {
4444
"jsdom": "^16.2.2",
4545
"tough-cookie": "^4.0.0",
46-
"user-agents": "^1.0.559",
47-
"vm2": "^3.9.2"
46+
"user-agents": "^1.0.559"
4847
},
4948
"devDependencies": {
5049
"eslint": "^7.0.0",

yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -1836,11 +1836,6 @@ [email protected]:
18361836
core-util-is "1.0.2"
18371837
extsprintf "^1.2.0"
18381838

1839-
vm2@^3.9.2:
1840-
version "3.9.2"
1841-
resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.2.tgz#a4085d2d88a808a1b3c06d5478c2db3222a9cc30"
1842-
integrity sha512-nzyFmHdy2FMg7mYraRytc2jr4QBaUY3TEGe3q3bK8EgS9WC98wxn2jrPxS/ruWm+JGzrEIIeufKweQzVoQEd+Q==
1843-
18441839
w3c-hr-time@^1.0.2:
18451840
version "1.0.2"
18461841
resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd"

0 commit comments

Comments
 (0)