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 glitchesRemove a cookie banner in PhantomJS by editing the page DOM after page.open succeeds and before page.render runs. Use a selector verified on the target site, remove or hide only that element, and add a wait when the banner appears asynchronously. Deleting cookies is a different operation: it changes browser state but does not remove an already-rendered banner.
What PhantomJS can—and cannot—do
PhantomJS exposes page-context JavaScript through page.evaluate and captures the resulting page with page.render. That makes visual removal of a consent banner possible without changing the site permanently. The selector is site-specific; there is no universal cookie-banner selector that works across all websites.
The project’s official homepage says that PhantomJS development is suspended until further notice: phantomjs.org. It can still be useful for maintaining an existing legacy job, but a new production pipeline should account for its unmaintained browser engine.
Remove the banner before rendering
- Create a
webpageobject. - Open the URL and check that the callback status is
success. - In the page context, select the verified banner element.
- Remove that element, or apply a temporary, narrowly scoped
display: nonestyle. - Call
page.renderonly after the DOM change (and any required wait).
Runnable PhantomJS example
Save this as hide-banner.js, replace the URL and selector, then run phantomjs hide-banner.js:
var page = require('webpage').create();
page.viewportSize = {
width: 1440,
height: 900
};
var targetUrl = 'https://example.com/';
page.open(targetUrl, function (status) {
if (status !== 'success') {
console.log('Page failed to load: ' + status);
phantom.exit(1);
return;
}
page.evaluate(function () {
var banner = document.querySelector('.cookie-consent');
if (banner) {
banner.parentNode.removeChild(banner);
}
});
page.render('page.png');
phantom.exit();
});
.cookie-consent is only an example. Inspect the target page and substitute the actual ID, class, or other selector. A selector that is too broad can remove a layout wrapper, navigation, or the page’s main content along with the consent UI.
Hide instead of deleting
Removing the node is usually cleanest, but hiding it can be safer when scripts expect the banner to remain in the DOM:
page.evaluate(function () {
var banner = document.querySelector('#onetrust-banner-sdk');
if (banner) {
banner.style.display = 'none';
}
});
Keep the change local to the screenshot run. Do not inject a global rule such as * { display:none }; it can blank the page or hide content that should be captured.
How to find a safe selector
Inspect the live markup
Open the site in a browser, inspect the visible consent panel, and identify the smallest element that contains the banner’s backdrop, text, and buttons. Prefer a stable ID supplied by the consent platform. If no ID exists, combine distinctive classes or an attribute, for example [aria-label="Cookie consent"]. Confirm that the selector matches one element and not an ancestor containing the whole application.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Account for platform-specific markup
Consent managers may insert their panel into a shadow root, an iframe, or the document after initial load. A normal document.querySelector cannot cross into an iframe, and a selector in the top document cannot directly reach a shadow root. If the panel is in an iframe, locate the frame and manipulate its document where PhantomJS’s frame support permits; otherwise the simple example will not match it. For a shadow root, inspect whether the legacy engine exposes the required DOM APIs before relying on that approach.
#1 Best Overall
Verify before changing anything
You can return a boolean from page.evaluate and log it in PhantomJS:
var found = page.evaluate(function () {
return !!document.querySelector('.cookie-consent');
});
console.log('Banner found: ' + found);
Run this against a representative page and fail loudly when the expected element is absent. A missing match may mean the site changed its markup, the banner is delayed, or the page loaded an error state.
Delayed banners and page readiness
The page.open callback indicates the navigation result, not that every later application update has finished. PhantomJS also provides onLoadFinished, but neither callback guarantees that a consent script scheduled after load has run. If the banner arrives asynchronously, wait for a known selector, use a site-specific readiness condition, or add a short delay before evaluating the removal.
var page = require('webpage').create();
var targetUrl = 'https://example.com/';
var output = 'page.png';
var waitMs = 1500;
page.open(targetUrl, function (status) {
if (status !== 'success') {
console.log('Open failed: ' + status);
phantom.exit(1);
return;
}
window.setTimeout(function () {
var removed = page.evaluate(function () {
var banner = document.querySelector('.cookie-consent');
if (!banner) {
return false;
}
banner.parentNode.removeChild(banner);
return true;
});
console.log('Banner removed: ' + removed);
page.render(output);
phantom.exit();
}, waitMs);
});
Choose the delay from the site’s behavior rather than copying a universal number. A fixed wait that is too short leaves the banner in the image; one that is too long wastes time on every capture. When possible, poll for a specific element or application-ready marker and impose a maximum timeout.
Deleting cookies is not banner removal
PhantomJS’s deleteCookie(cookieName) deletes matching cookies visible to the current URL. It changes stored state; it does not remove a banner element already in the DOM. In fact, deleting a consent cookie can make a site prompt again on the next visit because no consent state is saved.
| Operation | What changes | Effect on the screenshot |
|---|---|---|
Remove a DOM node with page.evaluate |
The current document’s markup | The selected banner is absent if done before page.render |
| Hide a node with inline style | The current document’s presentation | The node is not painted, while scripts may still find it |
deleteCookie |
Cookie state for the current URL | No direct visual change; a later visit may show the banner again |
Use cookie manipulation when you are testing consent-state behavior. Use DOM manipulation when the immediate goal is a clean image.
Rank #2
Prevent layout and capture mistakes
Preserve the page’s content area
Remove the overlay and backdrop together if they are separate nodes; otherwise a translucent scrim may remain. If deleting a parent would also remove meaningful content, hide only the fixed overlay and its panel. After the change, inspect the top, bottom, and sticky regions of the image for leftover overlays.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Control viewport and clipping
Set page.viewportSize before opening the page when responsive breakpoints matter. Use clipRect when you need a defined region rather than the complete viewport:
page.viewportSize = { width: 1366, height: 768 };
page.clipRect = { top: 0, left: 0, width: 1366, height: 768 };
Viewport dimensions can change which consent component is rendered, so verify the selector at every viewport your job supports.
Rank #3
Handle navigation and failures
Always branch on the status supplied by page.open. Do not render an error page as if it were a successful capture. Log the URL, status, selector-match result, and output path so a failed run can be diagnosed without opening every image.
Troubleshooting
The selector matches nothing
- Inspect the current page rather than relying on a selector from another site.
- Check whether the banner is injected after load; add a readiness wait.
- Check for an iframe or shadow root that requires a different access path.
- Confirm that the page did not redirect to an error or bot-check screen.
The banner still appears in the image
- Remove both the panel and its backdrop if they are separate elements.
- Move the evaluation immediately before
page.render. - Use a temporary style with higher specificity if a site script restores the element.
- Capture after the consent manager finishes its asynchronous update.
The page content disappears
- Your selector probably targets a wrapper or an ancestor of the main content.
- Replace it with the smallest banner node and test the match count.
- Prefer hiding the node first; switch to removal only after confirming the boundary.
The script exits before an image is written
- Call
phantom.exit()only afterpage.renderreturns. - Use an error exit for failed navigation and ensure every asynchronous branch reaches an exit path.
- Check that the destination directory is writable by the PhantomJS process.
A modern site renders incorrectly
PhantomJS uses an old, suspended browser engine. JavaScript syntax, TLS behavior, layout features, and bot defenses built for current browsers may fail or produce incomplete pages. Treat a broken render as an engine-compatibility risk, not merely a missing selector.
Or skip the browser setup
ScreenshotNeo is a hosted screenshot API and MCP server. It accepts a URL, handles the capture browser, and can remove consent banners, newsletter popups, and chat widgets before the shot. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP tools—take_screenshot, get_page_info, and capture_pdf—let Claude, Cursor, or another MCP client request captures.
Use the API documentation at screenshotneo.com/docs/ for the full option set. The one-call examples below use the supplied endpoint and return the image bytes.
cURL
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,
)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo provides 63 options, including full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF output, custom CSS and JavaScript, pre-capture clicks, selector hiding, waits for a selector or network idle, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Existing parameter names used by other screenshot APIs also work.
| Plan | Included shots | Price |
|---|---|---|
| Free | 1,000/month | $0; no card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Yearly billing gives two months free, and every feature is on every plan. Start with 1,000 free screenshots a month with no card; paid plans start at $5 for 3,000.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
When to keep PhantomJS and when to migrate
- Keep it temporarily: an established internal job has stable pages, a tested selector, and no requirement for modern browser behavior.
- Migrate local automation: you need a maintained browser engine, current JavaScript and CSS support, or complete control over a private network.
- Use a hosted API: you want a simple HTTP call, consent and popup cleanup, asynchronous or bulk jobs, or AI-agent access without managing a browser.
Whichever route you choose, treat banner removal as a page-specific transformation: verify the element, wait for the state you intend to capture, change the DOM narrowly, and render only after that change.
Frequently Asked Questions
Does removing a cookie banner submit consent?
No. DOM removal or hiding changes only the current screenshot document. It does not click an accept button or persist a consent choice.
Can one PhantomJS selector work for every website?
No. Consent platforms and site markup differ, and some banners are inside iframes or shadow roots. Selectors must be verified per site.
Why did deleting the consent cookie make the banner return?
Deleting the cookie removes the stored state that may suppress the prompt. On a later visit, the site can display the banner again.
Recommended Free Tools
Is PhantomJS suitable for a new production screenshot service?
Its official project page says development is suspended. That makes engine compatibility and long-term maintenance material risks for new systems.
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.

