question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: $ is not defined; how to pass jquery $ object to javascript injector method?

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: Latest
  • Platform / OS version: OSX
  • URLs (if applicable):
  • Node.js version: Latest

What steps will reproduce the problem?

 await page.addScriptTag({ content: `${functionToInject(codesChildArray)}`});
            var data =  await page.evaluate(function(codesChildArray){
            return functionToInject(codesChildArray);
            });
function functionToInject(codesChildArray){

    $( document ).ready(function() {
        console.log( "ready!" );
    });
    var myStringArray = ["Hello","World"];
    var arrayLength = myStringArray.length;
    for (var i = 0; i < arrayLength; i++) {
        console.log(myStringArray[i]);
    }

}

When Passing the ** codesChildArray** argument, it fails with an

ReferenceError: $ is not defined

Without the argument it works fine as expected. I need to Pass the array AND have jquery available true $ How can I make this work?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
toygansevimcommented, Feb 12, 2019

@aslushnikov I am still getting $ not defined error even though I have used: await page.addScriptTag({url: ‘https://code.jquery.com/jquery-3.2.1.min.js’});

4reactions
aslushnikovcommented, Apr 10, 2018

@voordev you should inject jquery separately into the page, then you’ll be able to use it inside functions you inject.

For example:

await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.3.1.slim.min.js'});

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: $ is not defined? - Stack Overflow
Show activity on this post. The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code ......
Read more >
3 Ways to Solve jQuery - Uncaught ReferenceError: $ is not ...
1) One of the most common reason of "ReferenceError: $ is not defined" in jQuery based application is that jQuery plugin is included...
Read more >
jQuery.parseHTML() | jQuery API Documentation
jQuery.parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These...
Read more >
AngularJS to Angular concepts: Quick reference
AngularJS event-based directives do not exist in Angular. Rather, define one-way binding from the template view to the component using event binding.
Read more >
Understanding the JavaScript Window Object - SitePoint
Learn about the browser's global object — the window object — which ... code will throw a ReferenceError if x has not been...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found