User Agents

Web browsers and everyday web tech, explained

How to Take Full Page Screenshot Chrome Extension

· 4 min read · Extensions

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

A full page screenshot captures the entire content of a web page, including sections not visible without scrolling. This is useful for documentation, reporting bugs, or saving long articles. Chrome extensions can automate this process using the browser’s built-in APIs, allowing users to capture the complete page with a single click. To achieve this, you’ll need to create or use a Chrome extension that leverages the chrome.tabs.captureVisibleTab and html2canvas or similar tools, combined with logic to stitch scrollable content. This guide walks through building or using such an extension effectively.

What You'll Need

  • A computer with Google Chrome installed
  • Basic understanding of HTML, JavaScript, and JSON
  • A text editor (e.g., VS Code, Sublime Text)
  • Developer mode enabled in Chrome Extensions
  • Optional: Node.js and npm (if using external libraries like html2canvas)

Step-by-Step

  1. Create a new folder for your extension. Name it something descriptive like full-page-screenshot.
  2. Create a manifest file named manifest.json inside the folder. For Chrome extensions using Manifest V3 (required since 2023), include the following minimum content:
    {
      "manifest_version": 3,
      "name": "Full Page Screenshot",
      "version": "1.0",
      "description": "Capture full page screenshots with one click.",
      "permissions": [
        "activeTab",
        "scripting"
      ],
      "action": {
        "default_popup": "popup.html"
      }
    }
    This grants the extension access to the active tab and allows it to inject scripts.
  3. Create popup.html in the same folder:
    <!DOCTYPE html>
    <html>
    <head>
      <style>
        button {
          width: 200px;
          height: 50px;
          font-size: 16px;
          margin: 10px;
        }
      </style>
    </head>
    <body>
      <button id="capture">Take Full Screenshot</button>
      <script src="popup.js"></script>
    </body>
    </html>
    This creates a simple popup with a button to trigger the screenshot.
  4. Create popup.js to handle the button click:
    document.getElementById('capture').addEventListener('click', async () => {
      const [tab] = await chrome.tabs.query({
        active: true,
        currentWindow: true
      });
    
      const script = {
        target: { tabId: tab.id },
        function: fullPageScreenshot
      };
    
      await chrome.scripting.executeScript(script);
    });
    
    function fullPageScreenshot() {
      // Create a canvas large enough for the full document
      const canvas = document.createElement('canvas');
      const context = canvas.getContext('2d');
      const { width, height } = document.documentElement;
    
      canvas.width = width;
      canvas.height = height;
    
      // Use CSS to hide scrollbars during capture
      document.body.style.overflow = 'hidden';
    
      // Render entire page to canvas (this is simplified; real implementation may use html2canvas)
      // For more accuracy, use a library like html2canvas via external script
    
      // Trigger download
      const dataURL = canvas.toDataURL('image/png');
      const a = document.createElement('a');
      a.href = dataURL;
      a.download = 'screenshot.png';
      a.click();
    }
    This script captures the full dimensions and triggers a download.
  5. Load the extension in Chrome: Go to chrome://extensions, enable Developer mode (top right), and click "Load unpacked". Select your extension folder.
  6. Test the extension: Navigate to any long webpage, click the extension icon, and press the "Take Full Screenshot" button. A PNG file should download.
  7. Improve accuracy with html2canvas (optional): Download html2canvas.min.js and include it in your extension. Update manifest.json to include it in "web_accessible_resources" and inject it before capture for better rendering of complex layouts.

Common Mistakes

  • Using Manifest V2 instead of V3: Chrome no longer supports V2 extensions. Always use manifest_version: 3.
  • Forgetting required permissions: Without activeTab and scripting, the extension cannot access page content.
  • Not testing on long pages: Short pages may not reveal issues with scrolling or canvas sizing.
  • Ignoring cross-origin restrictions: Extensions cannot capture content from Chrome settings or certain secure pages.
  • Overlooking styling during capture: Elements like fixed headers may appear multiple times if not handled.

Tips

  • Add a progress indicator in the popup for better UX on slow pages.
  • Use chrome.downloads.download() instead of simulated clicks for more reliable file saving.
  • Compress the image if file size is a concern (use JPEG for photos, PNG for text).
  • Handle high-DPI screens by scaling canvas size using window.devicePixelRatio.
  • Include error handling in JavaScript to catch failed captures gracefully.

Troubleshooting

If the screenshot fails or appears incomplete:

  • No download appears: Check that popups are allowed for the extension. Also verify that the scripting permission is present in the manifest.
  • Only visible part captured: The current method using canvas may not scroll. Implement a scroll-and-stitch technique or use html2canvas for full-page rendering.
  • Extension doesn’t load: Ensure the folder contains all required files and that there are no syntax errors in JSON or JavaScript.
  • Blank or black screenshot: This can happen with WebGL or video content. Try using chrome.tabs.captureVisibleTab with native rendering instead.
  • Security error: You cannot capture Chrome Web Store, settings, or other restricted URLs. Test on regular HTTP/HTTPS sites.

Frequently Asked Questions

Can I capture password-protected pages?

Yes, as long as you’re logged in and the page is loaded in the tab. The extension runs in your browsing context.

Does this work on all websites?

Most public websites work, but some with heavy anti-bot measures may block rendering. Also, Chrome-internal pages are restricted.

Can I save screenshots directly to Google Drive?

Not directly. The extension can only trigger downloads. You’d need to manually upload to Drive unless you integrate Drive API separately.

Is it possible to capture after a delay?

Yes. Add a setTimeout in the capture function to wait before taking the screenshot, useful for dynamic content.

Why is the image blurry on high-resolution screens?

The canvas may not account for device pixel ratio. Multiply canvas dimensions by window.devicePixelRatio for sharp output.

Can the extension capture multiple tabs at once?

Not in this basic version. You’d need to modify the script to loop through tabs using chrome.tabs.query and capture each individually.