<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: eracconseil</title>
    <description>The latest articles on DEV Community by eracconseil (@eracconseil).</description>
    <link>https://dev.to/eracconseil</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4027001%2Fca1e6e3d-fc43-4753-9c7b-7c4f9e778fba.jpg</url>
      <title>DEV Community: eracconseil</title>
      <link>https://dev.to/eracconseil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eracconseil"/>
    <language>en</language>
    <item>
      <title>How I handle lazy-loaded full-page screenshots in a Chrome Extension (MV3)</title>
      <dc:creator>eracconseil</dc:creator>
      <pubDate>Mon, 13 Jul 2026 09:30:10 +0000</pubDate>
      <link>https://dev.to/eracconseil/how-i-handle-lazy-loaded-full-page-screenshots-in-a-chrome-extension-mv3-204c</link>
      <guid>https://dev.to/eracconseil/how-i-handle-lazy-loaded-full-page-screenshots-in-a-chrome-extension-mv3-204c</guid>
      <description>&lt;p&gt;Most full-page screenshot tools have a dirty secret: they miss content that loads on scroll.&lt;/p&gt;

&lt;p&gt;Here's why — and how I fixed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Modern websites use lazy loading: images, sections, and components only render when they enter the viewport. A naive screenshot tool captures the page once, missing everything below the fold that hasn't loaded yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pre-scroll algorithm
&lt;/h2&gt;

&lt;p&gt;Before capturing anything, I scroll the entire page in steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;preScrollPage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;totalHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scrollHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;currentPos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentPos&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;totalHeight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrollTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentPos&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// wait for lazy-load to trigger&lt;/span&gt;
    &lt;span class="nx"&gt;currentPos&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;step&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Scroll back to top before capturing&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrollTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 150ms delay per step gives images time to start loading. After the full pre-scroll, I scroll back to top and start the actual capture.&lt;/p&gt;

&lt;h2&gt;
  
  
  MV3 service worker gotcha
&lt;/h2&gt;

&lt;p&gt;Chrome MV3 killed persistent background pages. My service worker goes idle between captures. The fix: use &lt;code&gt;chrome.scripting.executeScript&lt;/code&gt; with a content script that handles the entire capture loop, not the background script.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stitching 30+ screenshots
&lt;/h2&gt;

&lt;p&gt;Each capture segment is a base64 PNG. To stitch them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an offscreen canvas of &lt;code&gt;totalWidth × totalHeight&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Draw each segment at its &lt;code&gt;y&lt;/code&gt; offset&lt;/li&gt;
&lt;li&gt;Export as a single PNG blob&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The tricky part: the last segment often overlaps with the previous one if the page height isn't a perfect multiple of the viewport. I track &lt;code&gt;capturedHeight&lt;/code&gt; and clip the last segment accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fullpagescreenshot.pro" rel="noopener noreferrer"&gt;Full Page Screenshot Pro&lt;/a&gt; — now handles any page regardless of length, with lazy-loaded content fully captured.&lt;/p&gt;

&lt;p&gt;Happy to answer questions about Chrome extension development or the MV3 migration.&lt;/p&gt;

</description>
      <category>chromeextension</category>
    </item>
  </channel>
</rss>
