ReferenceError: $ is not defined; how to pass jquery $ object to javascript injector method?
See original GitHub issueSteps 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:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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’});
@voordev you should inject jquery separately into the page, then you’ll be able to use it inside functions you inject.
For example:
Hope this helps.