Free tools Windows power users keep installed
One-click scans. No signup required.
Use page.$eval() with a selector for the outer element, then call querySelector('img') inside the page-function callback. For a card whose image is nested in .thumbnail:
const src = await page.$eval(
'.card .thumbnail',
container => container.querySelector('img')?.src ?? null,
);
This returns the first nested image’s resolved DOM URL, or null when the image is absent. Use getAttribute('src') instead when you need the literal HTML attribute.
The basic nested-selector pattern
page.$eval() finds the first element matching its CSS selector, passes that element to your callback, and returns whatever the callback returns. The nested lookup therefore belongs inside the callback:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('https://example.com/products', {
waitUntil: 'domcontentloaded',
});
const src = await page.$eval(
'.card .thumbnail',
container => container.querySelector('img')?.src ?? null,
);
console.log(src);
await browser.close();
A descendant selector such as .card .thumbnail is preferable to a positional selector because it expresses the relationship between the card and its thumbnail. The callback runs in the page context, where container is the actual DOM element.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
What the returned value means
img.srcreturns the browser’s DOM URL property. A relative attribute such as/images/item.jpgis normally resolved to an absolute URL using the document’s base URL.- The optional chain returns
nullwhen the nestedimgdoes not exist. - The outer selector still must match. If no
.card .thumbnailexists,$evalthrows instead of returningnull.
Get the literal src attribute instead
Sometimes you need exactly what appeared in the HTML, without URL resolution. Call getAttribute('src') in the same callback:
const srcAttribute = await page.$eval(
'.card .thumbnail',
container => container.querySelector('img')?.getAttribute('src') ?? null,
);
This distinguishes a missing attribute from a present value and preserves relative URLs. Choose the property or attribute deliberately:
| Need | Use | Typical result |
|---|---|---|
| URL ready for downloading or storing | image.src |
Resolved absolute URL |
| Original HTML value | image.getAttribute('src') |
Literal value, possibly relative |
| Missing image should not fail the job | Either expression with ?. and ?? null |
null |
Extract images from every matching card
Use page.$$eval() when several outer elements are expected. It passes an array of all matching elements to the callback:
const srcs = await page.$$eval('.card .thumbnail', containers =>
containers.map(container =>
container.querySelector('img')?.src ?? null,
),
);
console.log(srcs);
The resulting array keeps the order of the matched containers. Entries are null when a card exists but has no nested image, so you can report incomplete cards without losing their positions.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Return only cards that contain an image
const imageUrls = await page.$$eval('.card .thumbnail', containers =>
containers
.map(container => container.querySelector('img')?.src ?? null)
.filter((src): src is string => src !== null),
);
Use the filtering form only when positional correspondence with the cards is not important.
Wait for dynamically inserted images
A page can render the container first and append its image later. Waiting for the outer element alone does not guarantee that the nested image is ready. Wait for the selector representing the state you actually need:
await page.goto('https://example.com/products', {
waitUntil: 'domcontentloaded',
});
await page.waitForSelector('.card .thumbnail img');
const src = await page.$eval(
'.card .thumbnail',
container => container.querySelector('img')?.src ?? null,
);
waitForSelector() waits for a matching element to appear in the relevant frame. If the site can legitimately render a card without an image, do not wait forever for an image selector; use a bounded timeout and handle the nullable result.
Wait for a specific card
await page.waitForSelector('.card[data-id="42"] .thumbnail img', {
timeout: 10000,
});
const src = await page.$eval(
'.card[data-id="42"] .thumbnail',
container => container.querySelector('img')?.src ?? null,
);
Use a stable data attribute or semantic class when available. Long chains such as div:nth-child(2) > div > img are more likely to break when the layout changes.
Recommended Free Tools
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Handle missing elements without masking errors
If absence is expected, probe the outer element with page.$() before evaluating it:
const container = await page.$('.card .thumbnail');
if (!container) {
console.warn('Thumbnail container was not found');
} else {
const src = await container.$eval(
'img',
image => image.src,
);
console.log(src);
}
page.$() resolves to null when nothing matches. In contrast, page.$$() resolves to an empty array, which is useful for an optional collection:
const containers = await page.$$('.card .thumbnail');
console.log(`Found ${containers.length} containers`);
Distinguish the two failure states
- Outer container missing: the page may be on the wrong route, still loading, or using a changed selector.
- Container present, image missing: the component may be intentionally empty, lazy-loaded, blocked, or using a different element such as
<picture>or a CSS background.
Log the selector and URL when diagnosing these cases. Avoid catching every exception and converting it to null; that can hide navigation and JavaScript failures.
Images in iframes, shadow roots, and unusual markup
Iframe content
Selectors run in the current document. For an image inside an iframe, first obtain the frame and then perform the same lookup in that frame:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteRank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const frameHandle = await page.waitForSelector('iframe.product-frame');
const frame = await frameHandle.contentFrame();
if (!frame) {
throw new Error('The iframe is not attached to a frame');
}
await frame.waitForSelector('.thumbnail img');
const src = await frame.$eval(
'.thumbnail',
container => container.querySelector('img')?.src ?? null,
);
The iframe’s document has its own URL base and DOM, so a selector from the top-level page will not cross into it.
Shadow DOM
For open shadow roots, use Puppeteer’s supported selector syntax or evaluate from the component that owns the shadow root. A normal document selector may stop at the shadow boundary. Keep the selector as close as possible to the component and verify it against the rendered DOM.
Responsive and lazy-loaded markup
Some components place the URL in data-src, srcset, or a <source> element until the image enters the viewport. In that case, img.src may be empty or point to a placeholder. Scroll the element into view, wait for the real image, or read the relevant attribute explicitly:
const dataSrc = await page.$eval(
'.card .thumbnail',
container => {
const image = container.querySelector('img');
return image?.getAttribute('data-src')
?? image?.getAttribute('src')
?? null;
},
);
TypeScript typing
TypeScript usually infers the callback value from the selector. If a specialized selector or return type needs help, annotate the result while still checking for a missing image:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
const src = await page.$eval(
'.card .thumbnail',
(container): string | null => {
const image = container.querySelector('img');
return image?.src ?? null;
},
);
Do not cast a possibly missing element without checking it. A cast can silence the compiler while leaving a runtime null dereference.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
failed to find element matching selector |
The outer selector matched nothing. | Check the URL, wait for the container, and verify the selector in the page’s rendered DOM. |
Result is null |
The container exists but has no nested img. |
Inspect alternate markup such as picture, data-src, or a background image. |
| Result is a placeholder URL | Lazy loading has not completed. | Scroll or trigger the component, then wait for the image selector or its src attribute. |
| Selector works in DevTools but not Puppeteer | Puppeteer queried before rendering, or the element is in an iframe/shadow root. | Wait for the nested selector and query the correct frame or shadow scope. |
| Relative URL is unexpected | You read the literal attribute. | Use image.src for the resolved DOM URL. |
| Only one URL is returned | $eval intentionally uses the first outer match. |
Use $$eval for all matching containers. |
Performance and reliability choices
- Use one
$$evalcall to extract many cards instead of issuing a separate round trip for every element. - Wait for the narrowest meaningful selector; waiting for an entire page or an arbitrary delay is slower and less deterministic.
- Prefer stable classes and data attributes over generated class names and positional selectors.
- Return plain strings or arrays from page functions. DOM handles are heavier and require explicit disposal in long-running jobs.
- Set navigation and selector timeouts appropriate to the site, and record the page URL, selector, and failure type for retries.
- For authenticated pages, establish cookies or headers before navigation; an image URL may also require the same session when downloaded later.
Or skip the browser setup
If your goal is a clean screenshot rather than DOM extraction, ScreenshotNeo provides a single-call website screenshot API. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response reports the result with X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
See the ScreenshotNeo API documentation for options such as full-page capture, CSS-selector element capture, device presets, custom JavaScript and CSS, waits, request blocking, cookies, headers, geolocation, PDFs, signed links, asynchronous jobs, and bulk capture.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account.
Frequently Asked Questions
Can I use a combined selector such as `.card .thumbnail img` with `$eval()`?
Yes, but the callback then receives the image itself. Use `page.$eval(‘.card .thumbnail img’, image => image.src)` when you do not need to distinguish the outer container from its nested image.
Why does `img.src` differ from the HTML shown in View Source?
The DOM property resolves relative URLs and can reflect client-side changes, while `getAttribute(‘src’)` returns the current literal attribute value.
How do I extract an image URL from a CSS background?
An element’s background is not an `img` element. Read `getComputedStyle(element).backgroundImage` in the page callback and parse the returned CSS value according to your application’s needs.
Quick Recap
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.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →

