html2canvas can appear to scroll your page to the top because it clones the document into a temporary iframe, writes the clone, and then restores the original page’s scroll position. A browser side effect during document.write, your own scroll or focus handlers, anchor links, or confusing the window scroll with a nested element’s scroll can all produce the same symptom. Record the scroll state, set scrollX/scrollY explicitly, handle nested containers with their own metrics, and use onclone for changes that should affect only the rendered copy.
What is actually scrolling?
html2canvas does not take a screenshot of the operating system window. It reads the DOM and computed styles, creates a cloned document in a temporary iframe, and paints that clone onto a canvas. Its document-cloning code contains a browser-specific workaround: after writing the cloned window, it restores the source document’s scroll position because Chrome can scroll the parent document as a side effect of the write.
That means a brief visual jump can happen while the clone is being prepared. A page that remains at the top after the promise resolves is not necessarily an html2canvas bug, however. Common independent causes include an href="#" link, a route transition, a focus call, or an event handler that invokes scrollTo(0, 0). A third class of problems occurs when the target is inside a scrollable child: window.scrollY describes the document, not that child’s scrollTop.
Diagnose the jump before changing code
Log the page and element state
Capture the offsets before and after rendering, and listen while the promise is pending. This shows whether the live page moves or only the generated image is positioned incorrectly.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
const target = document.querySelector('#capture');
const before = {
x: window.scrollX,
y: window.scrollY,
active: document.activeElement?.outerHTML?.slice(0, 200)
};
const onScroll = () => console.log('window scroll', window.scrollX, window.scrollY);
window.addEventListener('scroll', onScroll, { passive: true });
try {
const canvas = await html2canvas(target);
console.log('after render', {
x: window.scrollX,
y: window.scrollY,
before
});
} finally {
window.removeEventListener('scroll', onScroll);
}
If the scroll event fires at the same time as capture, temporarily disable application listeners, focus management, and links that navigate to a fragment. If the window offsets stay stable but the screenshot is displaced, fix the render coordinates instead of adding a global scrollTo call.
Fix a whole-page or viewport capture
Pass explicit negative window offsets
The options scrollX and scrollY are the coordinates used when html2canvas renders the clone. For a target that should match the currently visible viewport, compensate for the document’s current position:
const canvas = await html2canvas(document.body, {
scrollX: -window.scrollX,
scrollY: -window.scrollY
});
This negative-offset pattern is especially useful when the default coordinates make a capture look as though it has snapped to the top. It aligns the cloned viewport with the position the user was viewing. It is a rendering adjustment, not a guarantee that application code cannot scroll the live page.
Preserve the live position as a safety net
If another script can move the page, save and restore the position around the asynchronous operation. Do this only after identifying the competing handler; otherwise it can hide a real navigation or accessibility problem.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated 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 matchconst x = window.scrollX;
const y = window.scrollY;
try {
const canvas = await html2canvas(document.querySelector('#capture'), {
scrollX: -x,
scrollY: -y
});
// use canvas.toBlob(...) or canvas.toDataURL(...)
} finally {
window.scrollTo(x, y);
}
Do not use this pattern to cancel an intentional route change. If the page should navigate, remove the capture-time handler or prevent the unwanted default action instead.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
Capture a scrollable child correctly
Consider a panel with overflow: auto and a 500-pixel viewport. Its hidden content is controlled by scrollTop and scrollLeft; changing window.scrollY cannot reveal it. Inspect the child first:
const panel = document.querySelector('.results');
console.log({
clientWidth: panel.clientWidth,
clientHeight: panel.clientHeight,
scrollWidth: panel.scrollWidth,
scrollHeight: panel.scrollHeight,
scrollLeft: panel.scrollLeft,
scrollTop: panel.scrollTop
});
Option 1: capture the current panel view
Pass the panel itself and keep its current scroll state. The output represents what is visible inside that element, not all of its overflow.
const panel = document.querySelector('.results');
const canvas = await html2canvas(panel, {
scrollX: 0,
scrollY: 0
});
Option 2: temporarily expand the panel
To include all rows in one image, temporarily remove the clipping styles, capture, and restore them even if rendering fails.
const panel = document.querySelector('.results');
const old = {
height: panel.style.height,
maxHeight: panel.style.maxHeight,
overflow: panel.style.overflow
};
panel.style.height = `${panel.scrollHeight}px`;
panel.style.maxHeight = 'none';
panel.style.overflow = 'visible';
try {
const canvas = await html2canvas(panel, { scrollX: 0, scrollY: 0 });
// save or display canvas
} finally {
panel.style.height = old.height;
panel.style.maxHeight = old.maxHeight;
panel.style.overflow = old.overflow;
}
Expansion can reflow the page and alter sticky descendants. If changing the live DOM is undesirable, make the equivalent changes in onclone.
Use onclone for render-only changes
onclone receives the cloned document and cloned target. It is the safest place to hide buttons, remove sticky navigation, or alter overflow without flashing those changes to users.
const canvas = await html2canvas(document.querySelector('#capture'), {
scrollX: -window.scrollX,
scrollY: -window.scrollY,
onclone: (clonedDocument, clonedElement) => {
clonedDocument.querySelectorAll('.no-print, .chat-widget')
.forEach(node => node.remove());
clonedElement.querySelectorAll('.sticky, .fixed-toolbar')
.forEach(node => {
node.style.position = 'static';
});
}
});
Fixed and sticky elements are positioned relative to the viewport. Explicit scroll coordinates and clone-only CSS often prevent them from appearing at an unexpected offset. Keep the callback fast: expensive layout or network work delays capture and can make timing-sensitive pages appear inconsistent.
Full-page dimensions and canvas limits
For a large document, set the rendering viewport to the content dimensions deliberately:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →const element = document.querySelector('#long-page');
const canvas = await html2canvas(element, {
windowWidth: element.scrollWidth,
windowHeight: element.scrollHeight,
scrollX: 0,
scrollY: 0
});
This can expose content that is outside the current viewport, but it does not remove browser canvas limits. The html2canvas FAQ describes approximate maximum dimensions of about 32,767 pixels for current Chrome/Chromium, Firefox, and desktop Safari, with separate area limits and lower practical limits on iOS Safari. These are capability guidelines, not contractual constants; device memory, scale factor, and browser version matter.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Reduce the risk of blank or truncated output
- Prefer several smaller captures for very long reports, then stitch them outside the browser.
- Lower the effective pixel dimensions instead of requesting a huge retina scale.
- Remove unnecessary shadows, videos, and off-screen widgets in
onclone. - Test the same dimensions on the browsers and devices you support.
When html2canvas is the wrong execution environment
html2canvas depends on browser globals such as window, document, and computed styles, so it does not run directly in Node.js. For server-side generation, the project’s FAQ recommends driving a real browser with tools such as Puppeteer or Playwright. A headless browser can control navigation, wait for network idle, set a viewport, and capture a page without shipping capture code to every user.
Troubleshooting by symptom
The page visibly jumps, then returns
This is consistent with the clone/write side effect and restoration routine. Confirm with the scroll logger. If the final position is correct, avoid adding an artificial delay; use explicit coordinates only when the image itself is wrong.
The page stays at the top
Search for fragment links, focus calls, route transitions, and listeners that call scrollTo(0, 0). Disable them one at a time. Also check whether a component remounts during capture and resets its own scroll state.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Negative window offsets fix the page but not a panel
The panel has an independent scroll container. Read its scrollTop/scrollLeft, capture the visible element, or expand it temporarily as shown above.
Sticky headers cover content
Change their position or visibility in onclone. Do not mutate the production DOM merely to produce an image.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
The canvas is blank, clipped, or throws a size error
Reduce width, height, or scale; split the capture; and test on the target browser. Large dimensions can exceed per-browser area or memory limits even when each individual dimension appears valid.
Output differs from the page
Wait until fonts, images, and application data are ready. Check cross-origin image rules, because a resource that the browser will not expose to canvas can affect output. Then inspect clone-only styles and fixed-position elements.
Performance and reliability checklist
- Capture after the UI reaches a stable state, not immediately after a route change.
- Measure the target’s dimensions before choosing full-page settings.
- Use a moderate pixel scale and split oversized documents.
- Keep
onclonedeterministic and free of network requests. - Record browser, viewport, scroll container, and scale when debugging reports from users.
- For repeated server jobs, use a real headless browser rather than trying to run html2canvas without a DOM.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns PNG, JPEG, WebP, or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
Example cURL request (see the ScreenshotNeo documentation for all options):
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}`);
ScreenshotNeo also supports full-page and element captures, device and viewport settings, retina scale, PDF controls, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify migration.
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing provides two months free. Create a free ScreenshotNeo account to try it without a card.
Recommended Free Tools
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Frequently Asked Questions
Does html2canvas change the real page permanently?
Its cloning process is intended to restore the source scroll position, but your own handlers or navigation can still change the live page. Log scroll events and application state to distinguish the two.
Should I always use scrollY: -window.scrollY?
No. It is a useful viewport-alignment pattern. A nested scroll container, a deliberate full-page render, or a fixed-position layout may require different coordinates.
Can html2canvas capture content hidden by CSS overflow?
Not automatically in one visible-panel capture. Use the child’s scroll metrics and either capture its current view or temporarily expand it before rendering.
Can I use html2canvas in a Node.js script?
Not by itself; it requires browser APIs. Use a browser automation tool such as Puppeteer or Playwright for server-side screenshots.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsQuick 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.




