Chrome Extension Screenshot Tool — Developer Guide

4 min read

Build a Screenshot Capture Extension — Full Tutorial

What We’re Building

manifest.json

{
  "manifest_version": 3,
  "name": "Screenshot Tool",
  "version": "1.0.0",
  "permissions": ["activeTab", "downloads", "offscreen"],
  "action": { "default_popup": "popup.html" },
  "background": { "service_worker": "background.js" }
}

Step 1: Capture Visible Tab

// background.js
async function captureVisibleTab() {
  const dataUrl = await chrome.tabs.captureVisibleTab(null, {
    format: "png",
    quality: 100
  });
  return dataUrl; // "data:image/png;base64,..."
}

Step 2: Full Page Capture

// content.js
const messenger = createMessenger<Messages>();
const totalHeight = document.documentElement.scrollHeight;
const viewportHeight = window.innerHeight;

for (let y = 0; y < totalHeight; y += viewportHeight) {
  window.scrollTo(0, y);
  await new Promise(r => setTimeout(r, 100)); // Wait for render
  await messenger.sendMessage('captureViewport', { y, totalHeight, viewportHeight });
}

Step 3: Save to Downloads

async function saveScreenshot(dataUrl, filename) {
  const blob = await fetch(dataUrl).then(r => r.blob());
  const url = URL.createObjectURL(blob);
  await chrome.downloads.download({
    url: url,
    filename: `screenshots/${filename}`,
    saveAs: true  // Show save dialog
  });
}

Step 4: Copy to Clipboard (via Offscreen Document)

// background.js — create offscreen doc for clipboard access
await chrome.offscreen.createDocument({
  url: "offscreen.html",
  reasons: ["CLIPBOARD"],
  justification: "Copy screenshot to clipboard"
});

// offscreen.js — write image to clipboard
chrome.runtime.onMessage.addListener(async (msg) => {
  if (msg.type === "copyToClipboard") {
    const response = await fetch(msg.dataUrl);
    const blob = await response.blob();
    await navigator.clipboard.write([
      new ClipboardItem({ "image/png": blob })
    ]);
  }
});

Step 5: Popup UI

Step 6: Area Selection (Advanced)

Step 7: Simple Annotation

Testing

What You Learned

Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.


Turn Your Extension Into a Business

Ready to monetize? The Extension Monetization Playbook covers freemium models, Stripe integration, subscription architecture, and growth strategies for Chrome extension developers.

No previous article
No next article