The CLI starts the browser with a fresh profile. The site has never recorded your consent, so it displays its cookie banner, sometimes as a full-page overlay that dims the content. The extension runs in your browser, where you already dismissed the banner. This page describes three ways to save pages without the banner with the CLI.
1. Block the script of the consent manager
Most banners are displayed by a hosted consent manager (OneTrust, Cookiebot, Didomi, Quantcast, Usercentrics, Pubtech...). Blocking its script with the option --blocked-url-pattern removes the banner.
single-file https://www.sumologic.com/blog/kubernetes-deploy-postgres --blocked-url-pattern "cookielaw\.org"
To find the host to block, open the developer tools of your browser on the page, select the network tab and look for the script which displays the banner. The option can be repeated to block several hosts, e.g. when crawling several sites.
Some sites wait for the consent manager before displaying embedded content. If a page saved this way is incomplete, use the next method instead.
2. Dismiss the banner with a user script
autoconsent is the library used by the DuckDuckGo browsers to dismiss cookie banners. It contains rules for more than 300 consent managers and works with self-hosted banners too. It can be passed to the CLI as a user script with the option --browser-script.
npm install @duckduckgo/autoconsent
single-file https://www.sumologic.com/blog/kubernetes-deploy-postgres --browser-script node_modules/@duckduckgo/autoconsent/dist/autoconsent.standalone.js --browser-wait-delay 3000
The script clicks the button which rejects the cookies as soon as the banner is displayed. The option --browser-wait-delay gives it time to do it before the page is saved.
If the banner is not recognized, you can write a user script which removes it just before the page is saved, see How to execute a user script before a page is saved. This script removes the banner displayed by OneTrust.
dispatchEvent(new CustomEvent("single-file-user-script-init"));
addEventListener("single-file-on-before-capture-request", () => {
document.querySelectorAll("#onetrust-consent-sdk").forEach(element => element.remove());
});
3. Save your consent in a browser profile
With Chromium, you can dismiss the banner once in a visible browser window and reuse its profile. Run the command below, dismiss the banner in the window that opens, then quit the browser to save the profile.
single-file --create-browser-profile my-profile https://www.sumologic.com/blog/kubernetes-deploy-postgres
Then pass the profile to the CLI when saving pages.
single-file https://www.sumologic.com/blog/kubernetes-deploy-postgres --browser-profile my-profile
The profile is copied before the browser starts and is never modified by the CLI, so you can reuse it for all your captures. This method also works for pages which require a logged-in session.