Menu

Finding every image on a page from a content script, and the lazy iframe that cost 8 seconds
📰

Finding every image on a page from a content script, and the lazy iframe that cost 8 seconds

DEV Community: javascript·Casper Tran·about 2 hours ago
#glUkTA2f
#devtojavascript#devto#dev#every#walk
Long article (1716 words) — no AI summary yet.
Reading 0:00
15s threshold

The browser already knows every image it has loaded, but an extension cannot ask it for that list. chrome.webRequest only shows requests while you listen, and it never sees an image that has not loaded yet: the lazy one 3,000 px below the fold, the one still sitting in data-src , the one a script will copy into place on scroll. So my extension, PixLasso, does it the hard way. It injects one content script into every frame and walks the DOM.

Below: what the walk looks at besides <img> , what it costs on a page with a third of a million elements, and how one off-screen iframe made every scan wait 8 seconds.

One script, every frame, the last expression is the result

The scan is a single file run with chrome.scripting.executeScript . It is an IIFE, and the value of the last expression comes back to the service worker, one result per frame:

const results = await chrome . scripting .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.