Error when running JSDOM.fromURL on a website using jQuery
Basic info:
- Node.js version: 12.10.0
- jsdom version: 16.2.2
Minimal reproduction case
const { JSDOM } = require("jsdom")
const options = {
runScripts: 'dangerously'
};
// Example url
const url = 'https://skillpvp.fr/'
JSDOM.fromURL(url, options)
.then((dom) => {
const wantedValue = dom.window
})
.catch(() => { })
Explanations
When I run this code on a website using Jquery, the wantedValue variable is fine, I get the value I want.
But my Node.js console is full of Error: Uncaught [ReferenceError: $ is not defined].
The catch doesn't seem to work here. Is it possible to catch errors from external scripts like this ? Or to pass jQuery as dependence to jsdom ?
Errors:
(I get multiple times this same error).
Error: Uncaught [ReferenceError: $ is not defined]
at reportException (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\helpers\runtime-script-errors.js:62:24)
at processJavaScript (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:243:7)
at HTMLScriptElementImpl._innerEval (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:176:5)
at C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:115:12
at ResourceQueue.push (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\browser\resources\resource-queue.js:53:16)
at HTMLScriptElementImpl._fetchInternalScript (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:114:21)
at HTMLScriptElementImpl._eval (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:170:12)
at HTMLScriptElementImpl._poppedOffStackOfOpenElements (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:133:10)
at OpenElementStack.pop (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\browser\parser\html.js:43:12)
at Object.endTagInText [as END_TAG_TOKEN] (C:\code\jsdom-test\node_modules\parse5\lib\parser\index.js:2153:20) ReferenceError: $ is not defined
at https://skillpvp.fr/:2:5
at Script.runInContext (vm.js:137:20)
at Object.runInContext (vm.js:300:6)
at processJavaScript (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:241:10)
at HTMLScriptElementImpl._innerEval (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:176:5)
at C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:115:12
at ResourceQueue.push (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\browser\resources\resource-queue.js:53:16)
at HTMLScriptElementImpl._fetchInternalScript (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:114:21)
at HTMLScriptElementImpl._eval (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:170:12)
at HTMLScriptElementImpl._poppedOffStackOfOpenElements (C:\code\jsdom-test\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:133:10)
I can't reproduce this because you have not provided a real URL, or an example of the output.
@domenic Sorry for that, I've updated the issue.
I get the same issue when running code like this
let jsdom = require('jsdom');
let { JSDOM } = jsdom;
JSDOM.fromURL("https://www.us-proxy.org/", { runScripts: 'dangerously' }).then(dom => {
console.log(dom.serialize());
});
Can confirm behavior. I am running on sites anger many different errors no matter what way I try.
Having the same issue.
Have the same issue:
const dom = await JSDOM.fromURL(homepage, {runScripts: 'dangerously'});
console.log(dom.window.jQuery);
It returns undefined and this error is shown:
Error: Uncaught [ReferenceError: $ is not defined]
at reportException (jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)
at processJavaScript (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:243:7)
at HTMLScriptElementImpl._innerEval (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:176:5)
at jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:115:12
at ResourceQueue.push (jsdom/lib/jsdom/browser/resources/resource-queue.js:53:16)
at HTMLScriptElementImpl._fetchInternalScript (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:114:21)
at HTMLScriptElementImpl._eval (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:170:12)
at HTMLScriptElementImpl._poppedOffStackOfOpenElements (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:133:10)
at OpenElementStack.pop (jsdom/lib/jsdom/browser/parser/html.js:43:12)
at Object.endTagInText [as END_TAG_TOKEN] (parse5/lib/parser/index.js:2153:20) ReferenceError: $ is not defined
at https://www.sid.ir/fa/journal/:1:1
at Script.runInContext (node:vm:144:12)
at Object.runInContext (node:vm:295:6)
at processJavaScript (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:241:10)
at HTMLScriptElementImpl._innerEval (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:176:5)
at jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:115:12
at ResourceQueue.push (jsdom/lib/jsdom/browser/resources/resource-queue.js:53:16)
at HTMLScriptElementImpl._fetchInternalScript (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:114:21)
at HTMLScriptElementImpl._eval (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:170:12)
at HTMLScriptElementImpl._poppedOffStackOfOpenElements (jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:133:10)
I have the same issue. I'm so surprised that this issue has not been answered for so long.
Error message is same with yours, starts with Error: Uncaught [ReferenceError: $ is not defined].
And also the error message repeats twice.
My code is:
axios.get('https://covid19.saglik.gov.tr/').then(response => {
const html = response.data;
const window = new JSDOM(html, {
runScripts: 'dangerously',
}).window;
});
How is this still not answered? Still getting this error. And no solution to be found.
Also getting this error. Appears to have been one since 2012. No fix in sight?
+1
To everyone wondering why this is still an issue: Please don't feel entitled to anything when it comes to open source software. Instead, feel free to step up and contribute money or time to fix it.
jsdom is a community-driven project maintained by a team of volunteers