October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Convert a Puppeteer Handle to a String

Puppeteer’s handle.toString() describes the handle for debugging. Learn how to retrieve actual element text or serializable values instead.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call handle.toString() to get a string representation of the Puppeteer handle itself. That representation is useful for debugging; it is not the text of the element or a general-purpose serialization of the object. To retrieve page content, evaluate a function on the handle instead.

Get the handle’s string representation

Use toString() directly:

const description = handle.toString();
console.log(description);

Puppeteer documents this as a debugging aid. The returned representation describes the handle, not necessarily the value you want to extract from the page. See the Puppeteer JSHandle API.

As an Amazon Associate I earn from qualifying purchases.

Get the value behind the handle instead

Choose the method according to the output you need. These examples assume you already have a Puppeteer handle.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Use Example
A string representation of the handle, typically for debugging toString() handle.toString()
Text or another selected value from the referenced page object evaluate() await handle.evaluate(el => el.textContent)
Serializable portions of the referenced value jsonValue() await handle.jsonValue()
A result that should remain an in-page handle evaluateHandle() await page.evaluateHandle(() => document.body)

Read an element’s text or attribute

For an element handle, evaluate a function with the element as its argument, then return the property you need:

const text = await elementHandle.evaluate(el => el.textContent);
const title = await elementHandle.evaluate(el => el.getAttribute('title'));

Use textContent when you want the text content represented in the DOM. If you specifically need rendered, human-visible text, innerText may be a better fit:

const visibleText = await elementHandle.evaluate(el => el.innerText);

Retrieve serializable data

jsonValue() returns serializable portions of the referenced value. Puppeteer notes that it does not call the referenced object’s toJSON() method, so do not assume custom JSON conversion will be applied.

const value = await handle.jsonValue();

Choose between a returned value and a continuing handle

page.evaluate() returns the result of the page-side function. page.evaluateHandle() instead wraps the result as a handle that you can continue using in the page context. Use the latter when you need to keep a reference rather than just receive a value. See the Puppeteer page API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Release handles when finished

A handle keeps its referenced object from being garbage-collected until the handle is disposed. Puppeteer also documents automatic disposal when the associated frame navigates or the parent execution context is destroyed. When you are done with a handle, release it explicitly:

await handle.dispose();

Do not use the handle after disposal. If a navigation or context destruction has already invalidated it, acquire a fresh handle from the current page context.

Troubleshooting

  • toString() does not show the element’s text: That is expected; it represents the handle. Read text with await elementHandle.evaluate(el => el.textContent).
  • jsonValue() does not produce the custom JSON shape you expected: Puppeteer does not call the referenced object’s toJSON() method. Explicitly construct and return the fields you need inside evaluate().
  • A handle fails after navigation or context destruction: Puppeteer automatically disposes handles in these situations. Query the page again to obtain a new handle.
  • You no longer need a handle: Call dispose() so its referenced object is no longer retained by that handle.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If the end goal is a screenshot rather than inspecting a Puppeteer value, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return an image or PDF; the example below saves a WebP capture. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups and chat widgets before capture. Bot checks, blank pages and failed loads are not billed; its MCP server lets AI agents take screenshots; and the Free plan includes 1,000 screenshots a month with no card, while paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month—no card required.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.