Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

633
Views
What is the difference between jsHandle and elementHandle in Puppeteer?

I have been reading Puppeteer API documentation, they have jsHandle and elementHandle (which they state being an extension of jsHandle).

It seems functions like page.evaluateHandle page.$ page.$$ can all return jsHandle/elementHandle which is like an object that exists in-page.

So my question what is jsHandle/elementHandle and what are the differences between the two besides one being an extension of the other?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The docs say:

class: JSHandle

JSHandle represents an in-page JavaScript object. JSHandles can be created with the page.evaluateHandle method.

const windowHandle = await page.evaluateHandle(() => window);

and

class: ElementHandle

extends: JSHandle

ElementHandle represents an in-page DOM element. ElementHandles can be created with the page.$ method.

const hrefElement = await page.$('a');

In JavaScript, all non-primitives are objects. Many things you can reference in a page - such as the window in the example above - are objects that you can get a JSHandle for.

If you can run native JavaScript on the website and get a reference to a value that isn't a primitive, though any method, that's an object, that could potentially be wrapped in a JSHandle in Puppeteer.

ElementHandle, on the other hand, is more particular. It represents an element. HTMLElements are objects, but not all objects are HTMLElements. There are some methods that you can do with an element (and an ElementHandle) that don't make sense with generic objects. For example, given an ElementHandle, you could try to select a descendant of it with .$ or .$$ in Puppeteer.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!