Chrome extensions cannot pass a rectangle directly to chrome.tabs.captureVisibleTab(). The reliable approach is to capture the visible tab once, show that image in an extension page or offscreen document, let the user drag a selection rectangle, convert the displayed coordinates to bitmap pixels, and crop the image with a canvas. This avoids repeated captures, respects Chrome’s two-calls-per-second limit, and works with Manifest V3’s service-worker restrictions.
What the API captures—and what it does not
chrome.tabs.captureVisibleTab() returns an image data URL for the visible viewport of a tab. It does not accept x, y, width, or height parameters for an arbitrary page region. Therefore, a selected-area workflow has two phases:
- Capture the viewport once.
- Crop the user’s rectangle locally from the returned bitmap.
The screenshot’s pixel dimensions may differ from the displayed image’s CSS dimensions because of device scale and browser rendering. Always calculate scale from the bitmap’s actual width and height divided by the displayed image’s width and height. Do not assume that devicePixelRatio is the correct value.
See Chrome’s tabs API reference for capture behavior, permissions, and limits.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#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.
Permissions and Manifest V3 setup
Use activeTab for a user-invoked tool
For an extension activated by a button, context menu, or keyboard command, activeTab grants temporary access to the current tab after the user invokes the extension. It generally avoids an install-time host-permission warning. You can instead request <all_urls> when your product genuinely needs persistent access to many sites.
captureVisibleTab() accepts either activeTab or <all_urls>. Chrome pages and other sensitive pages can be captured with activeTab; file URLs require the user to enable file access for the extension.
Minimal manifest
{
"manifest_version": 3,
"name": "Area Capture",
"version": "1.0.0",
"permissions": ["activeTab", "scripting"],
"action": { "default_title": "Capture area" },
"background": { "service_worker": "service-worker.js" },
"web_accessible_resources": [{
"resources": ["selector.html", "selector.js"],
"matches": ["<all_urls>"]
}]
}
The tabs permission is not required merely to call the chrome.tabs namespace. It exposes sensitive tab properties such as URL and title; capture access is controlled separately by activeTab or host permissions.
Capture once, then open a selector
The service worker should perform the capture immediately after the user action. It has no DOM, so it should not attempt to create an image element or canvas. Send the data URL to an extension page, popup, or offscreen document for display and cropping.
Recommended Free Tools
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.
Service worker
chrome.action.onClicked.addListener(async (tab) => {
if (!tab.id) return;
try {
const dataUrl = await chrome.tabs.captureVisibleTab(tab.windowId, {
format: "png"
});
await chrome.storage.session.set({
areaCapture: { tabId: tab.id, dataUrl }
});
await chrome.tabs.create({
url: chrome.runtime.getURL("selector.html")
});
} catch (error) {
console.error("Visible-tab capture failed", error);
}
});
If you do not want to open a tab, use an extension popup or an offscreen document. Chrome’s offscreen API provides a hidden extension document with DOM access and is available for MV3 in Chrome 109 and later.
Build the selection UI
The selector displays the captured bitmap at a constrained size, tracks pointer movement, and draws a rectangle over it. Capture is not repeated while the pointer moves; only the local overlay changes.
selector.html
<!doctype html>
<meta charset="utf-8">
<title>Select an area</title>
<style>
body { margin: 0; font: 14px system-ui; background: #222; color: #fff; }
#stage { position: relative; display: inline-block; line-height: 0; }
#shot { max-width: 100vw; max-height: 90vh; user-select: none; }
#selection { position: absolute; border: 2px solid #28a9ff; background: rgb(40 169 255 / 20%); pointer-events: none; }
#save { margin: 12px; padding: 8px 14px; }
</style>
<div id="stage"><img id="shot" alt="Captured tab"><div id="selection" hidden></div></div>
<button id="save" disabled>Save selection</button>
<script src="selector.js"></script>
selector.js
const image = document.querySelector("#shot");
const box = document.querySelector("#selection");
const save = document.querySelector("#save");
let start = null;
let rect = null;
const stored = await chrome.storage.session.get("areaCapture");
if (!stored.areaCapture?.dataUrl) throw new Error("No captured image");
image.src = stored.areaCapture.dataUrl;
await image.decode();
stage.addEventListener("pointerdown", (event) => {
const r = image.getBoundingClientRect();
start = {
x: Math.max(0, Math.min(event.clientX - r.left, r.width)),
y: Math.max(0, Math.min(event.clientY - r.top, r.height))
};
rect = { x: start.x, y: start.y, w: 0, h: 0 };
box.hidden = false;
stage.setPointerCapture(event.pointerId);
});
stage.addEventListener("pointermove", (event) => {
if (!start) return;
const r = image.getBoundingClientRect();
const x = Math.max(0, Math.min(event.clientX - r.left, r.width));
const y = Math.max(0, Math.min(event.clientY - r.top, r.height));
rect = {
x: Math.min(start.x, x), y: Math.min(start.y, y),
w: Math.abs(x - start.x), h: Math.abs(y - start.y)
};
Object.assign(box.style, {
left: `${rect.x}px`, top: `${rect.y}px`,
width: `${rect.w}px`, height: `${rect.h}px`
});
save.disabled = rect.w < 1 || rect.h < 1;
});
stage.addEventListener("pointerup", () => { start = null; });
save.addEventListener("click", () => {
const scaleX = image.naturalWidth / image.getBoundingClientRect().width;
const scaleY = image.naturalHeight / image.getBoundingClientRect().height;
const sx = Math.round(rect.x * scaleX);
const sy = Math.round(rect.y * scaleY);
const sw = Math.max(1, Math.round(rect.w * scaleX));
const sh = Math.max(1, Math.round(rect.h * scaleY));
const canvas = document.createElement("canvas");
canvas.width = Math.min(sw, image.naturalWidth - sx);
canvas.height = Math.min(sh, image.naturalHeight - sy);
canvas.getContext("2d").drawImage(
image, sx, sy, canvas.width, canvas.height,
0, 0, canvas.width, canvas.height
);
const link = document.createElement("a");
link.download = "selected-area.png";
link.href = canvas.toDataURL("image/png");
link.click();
});
This code uses separate horizontal and vertical scale factors. That is safer than one assumed ratio when CSS sizing, borders, or layout constraints affect the displayed image.
MV3 architecture: extension page or offscreen document
Service workers cannot use DOM APIs such as document.createElement("canvas"). Keep image decoding, pointer handling, and canvas cropping in an extension page, popup, or offscreen document. The offscreen document is useful when you need hidden processing or want the worker to remain the coordinator. Chrome’s screen-capture guide explains the offscreen pattern for media capture and processing: screen capture guidance.
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.
When another capture API is the right choice
| Requirement | API | Why |
|---|---|---|
| One still image of the visible viewport to crop | chrome.tabs.captureVisibleTab() |
Returns an image data URL; crop it locally. |
| Ongoing tab video or audio | chrome.tabCapture |
Provides a media stream for recording or processing. |
| DOM APIs from MV3 background logic | chrome.offscreen |
Provides a hidden extension document with DOM access. |
getDisplayMedia() presents a browser chooser for a tab, window, or screen. For a known active tab and a user-initiated stream, Chrome documents tabCapture; from Chrome 116, a service worker can obtain a stream ID after invocation and pass it to an offscreen document. Those APIs solve streaming and recording, not a simple cropped still.
Performance, limits, and image quality
- Chrome documents a maximum of two
captureVisibleTab()calls per second (Chrome 92+), and describes capture as expensive. Capture once per selection operation. - PNG preserves sharp text but can produce large data URLs. JPEG is smaller for photographic pages and supports a quality option where applicable; WebP is another compact choice.
- Large full-viewport bitmaps consume memory in the image element and canvas. Release references after saving and avoid keeping multiple data URLs in storage.
- The method captures only what is visible in the viewport. It does not automatically produce a full-page screenshot or include content below the fold.
- Cross-origin content shown in the captured bitmap is already rasterized by Chrome; the crop operation does not read the page’s DOM or pixels directly.
Troubleshooting
“Cannot access contents of the page”
Confirm that the action was user initiated and that activeTab is present. For file URLs, enable “Allow access to file URLs” on the extension’s details page. Do not assume tabs permission fixes capture access.
The image is blank or the wrong tab was captured
Pass the correct windowId from the clicked tab and capture immediately. Do not rely on a later active-tab query after opening another extension page. Restricted browser UI pages may still impose capture restrictions.
The crop is offset or the wrong size
Use image.naturalWidth / image.getBoundingClientRect().width and the corresponding height ratio. Account for the image’s actual bounding rectangle, not the page viewport or assumed device-pixel ratio.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #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
Nothing happens in the service worker
Move all DOM and canvas code into an extension page or offscreen document. The worker can capture, store, and message; it cannot render the selection interface.
Captures fail during rapid testing
Throttle calls to two per second or less. Pointer movement should update only the overlay and crop locally; it should never trigger another capture.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If you need a screenshot service rather than an in-extension capture workflow, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. It also provides an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
Using the API requires an access key. The complete parameter list is in the ScreenshotNeo documentation.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchescURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
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)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Plans include 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
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.
FAQ
Can I pass a CSS selector to captureVisibleTab()?
No. Capture the viewport, then crop pixels, or use script injection to measure an element before cropping.
Can I capture an element in an iframe?
You can use chrome.scripting.executeScript() to inspect a permitted frame and obtain coordinates, but the final visible-tab image still needs pixel-coordinate cropping. The scripting API requires the scripting permission plus matching host access or activeTab; see its reference.
Should I use tabCapture for a still image?
Use tabCapture when you need a stream or recording. For one cropped still, captureVisibleTab() followed by canvas cropping is simpler.
Free tools Windows power users keep installed
One-click scans. No signup required.
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.

