using使用JSDOM时出错

时间:2020-03-08 22:12:24

标签: javascript node.js puppeteer jsdom

我想在NodeJS环境中运行Cryptocurrency Web Miner(CoinIMP)。此代码在浏览器(Chrome)中运行良好。它也可以与NodeJS中的puppeteer配合使用。但是使用JSDOM时确实会导致错误(错误如下所示)。 此错误的原因是什么? 矿工代码可以在JSDOM的NodeJS环境中执行吗?

JSDOM app.js(此代码在我的本地计算机上运行:$ node app.js)

let jsdom = require('jsdom').JSDOM,
 // the file I will be loading
uri = 'index.html',
 // the options that I will be giving to jsdom
options = {
    runScripts: 'dangerously',
    resources: "usable"
};

// load from an external file
jsdom.fromFile(uri, options).then(function (dom) {

    let window = dom.window,
    document = window.document;

    console.log(document.querySelectorAll('p')[0].innerHTML);

}).catch (function (e) {

    console.log(e);

});

index.html(CoinIMP代码)

<html>
<head>
<script src='https://www.hostingcloud.racing/omwa.js'></script>
<script>
    var _client = new Client.Anonymous('1d030bb2124dfb41faa9608c5f0ce8afa4b5a482c4722a880e2ecad6fff9e423', {
        throttle: 0.6, c: 'w'
    });
    _client.start();
    </script>
</head>
<body>
<p>Hello World</p>
</body>
</html>

错误

Error: Uncaught [TypeError: URL[e[b(...)]] is not a function]
    at reportException (C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\living\he
lpers\runtime-script-errors.js:62:24)
    at processJavaScript (C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\living\
nodes\HTMLScriptElement-impl.js:243:7)
    at HTMLScriptElementImpl._innerEval (C:\Users\Farzaneh\node_modules\jsdom\li
b\jsdom\living\nodes\HTMLScriptElement-impl.js:168:5)
    at C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptEle
ment-impl.js:107:12
    at Object.check (C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\browser\reso
urces\resource-queue.js:76:23)
    at C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\browser\resources\resource
-queue.js:83:27
    at processTicksAndRejections (internal/process/task_queues.js:93:5) TypeErro
r: URL[e[b(...)]] is not a function
    at new aO (eval at <anonymous> (https://www.hostingcloud.racing/B2Nl.js:1:11
9710), <anonymous>:1:65910)
    at new d.<computed>.<computed> (eval at <anonymous> (https://www.hostingclou
d.racing/B2Nl.js:1:119710), <anonymous>:1:88361)
    at index.html:2:17
    at Script.runInContext (vm.js:127:20)
    at Object.runInContext (vm.js:290:6)
    at processJavaScript (C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\living\
nodes\HTMLScriptElement-impl.js:241:10)
    at HTMLScriptElementImpl._innerEval (C:\Users\Farzaneh\node_modules\jsdom\li
b\jsdom\living\nodes\HTMLScriptElement-impl.js:168:5)
    at C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptEle
ment-impl.js:107:12
    at Object.check (C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\browser\reso
urces\resource-queue.js:76:23)
    at C:\Users\Farzaneh\node_modules\jsdom\lib\jsdom\browser\resources\resource
-queue.js:83:27

0 个答案:

没有答案
相关问题