Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

634
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda