jsdom icon indicating copy to clipboard operation
jsdom copied to clipboard

Error when running JSDOM.fromURL on a website using jQuery

Open vkaelin opened this issue 5 years ago • 11 comments

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)

vkaelin avatar Apr 22 '20 11:04 vkaelin

I can't reproduce this because you have not provided a real URL, or an example of the output.

domenic avatar Apr 22 '20 13:04 domenic

@domenic Sorry for that, I've updated the issue.

vkaelin avatar Apr 22 '20 14:04 vkaelin

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());
});

Jacobboogiebear avatar Apr 25 '20 22:04 Jacobboogiebear

Can confirm behavior. I am running on sites anger many different errors no matter what way I try.

aarock1234 avatar May 22 '20 19:05 aarock1234

Having the same issue.

Ron-SSG avatar Jul 23 '20 12:07 Ron-SSG

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)

bmamouri avatar Feb 08 '21 03:02 bmamouri

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;
});

furkanalptokac avatar Jul 25 '21 10:07 furkanalptokac

How is this still not answered? Still getting this error. And no solution to be found.

MrSelfisH01 avatar Jan 09 '23 20:01 MrSelfisH01

Also getting this error. Appears to have been one since 2012. No fix in sight?

loudar avatar May 22 '23 15:05 loudar

+1

neontorrent avatar Oct 16 '24 22:10 neontorrent

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

sedot42 avatar Mar 27 '25 11:03 sedot42