Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running JSDOM.fromURL on a website using jQuery #2952

Open
vkaelin opened this issue Apr 22, 2020 · 10 comments
Open

Error when running JSDOM.fromURL on a website using jQuery #2952

vkaelin opened this issue Apr 22, 2020 · 10 comments

Comments

@vkaelin
Copy link

vkaelin commented Apr 22, 2020

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)
@domenic
Copy link
Member

domenic commented Apr 22, 2020

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

@vkaelin
Copy link
Author

vkaelin commented Apr 22, 2020

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

@Jacobboogiebear
Copy link

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

@aarock1234
Copy link

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

@Ron-SSG
Copy link

Ron-SSG commented Jul 23, 2020

Having the same issue.

@bmamouri
Copy link

bmamouri commented Feb 8, 2021

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)

@furkanalptokac
Copy link

furkanalptokac commented Jul 25, 2021

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

@MrSelfisH01
Copy link

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

@loudar
Copy link

loudar commented May 22, 2023

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

@neontorrent

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants