Removing Browser History in Puppeteer Node.js with Visible Chrome Window

I’m trying to delete the browsing history in a visible Chrome browser (headless=false) using Node.js Puppeteer but my attempts are failing.

await browser.goto('chrome://settings/clearBrowserData');
await browser.keyboard.press('Enter');

Another approach I tested:

await browser.keyboard.down('Control');
await browser.keyboard.down('Shift');
await browser.keyboard.down('Delete');
await browser.keyboard.press('Enter');

I also experimented with .evaluate() and .click() methods but none of these solutions worked for me. Has anyone successfully cleared browsing data programmatically using Puppeteer? I need a working solution for this automation task.

yea, chrome settings can be tricky! try using the chrome devtools protocol (CDP) to clear browsing data instead, it’s way more reliable than messing with the settings page. also launching with --disable-web-security might help. gl!

I’ve hit this same issue tons of times. Chrome settings pages are a nightmare to automate - they break constantly.

Skip the UI entirely. Use Chrome DevTools Protocol instead:

const client = await page.target().createCDPSession();
await client.send('Storage.clearDataForOrigin', {
  origin: '*',
  storageTypes: 'all'
});

For browsing history:

await client.send('Storage.clearDataForOrigin', {
  origin: '*', 
  storageTypes: 'cookies,local_storage,indexeddb,websql,cache_storage'
});

Honestly though, this stuff gets messy quick. I moved to Latenode for browser automation because it wraps all the CDP headaches into simple drag-and-drop nodes.

No more writing brittle code that breaks every Chrome update. Just connect the browser actions you want and it handles the protocol stuff automatically.

Saved me countless hours debugging weird browser quirks.

Had the same issue last month with a web scraping project. Keyboard shortcuts never worked reliably - Chrome just ignores them when launched through Puppeteer.

Here’s what actually fixed it - launch Chrome with flags to start fresh every time:

const browser = await puppeteer.launch({
  headless: false,
  args: [
    '--user-data-dir=/tmp/chrome-clean-session',
    '--no-first-run',
    '--disable-background-mode'
  ]
});

This creates a temp user data directory that gets wiped between runs. Way simpler than clearing history mid-session. If you really need to clear during runtime, use the CDP BrowsingData method mentioned above, but honestly the clean launch approach works better.

Your code’s calling goto() on the browser object instead of a page. That won’t work. Chrome internal pages need CDP commands, not regular navigation.

Here’s what actually works:

const page = await browser.newPage();
const client = await page.target().createCDPSession();

// Clear browsing history specifically
await client.send('BrowsingData.clearBrowsingData', {
  options: {
    since: 0
  },
  dataToRemove: {
    browsingHistory: true,
    downloadHistory: true,
    formData: true
  }
});

I’ve used this approach for over two years in production. The BrowsingData.clearBrowsingData method is built for history removal - way better than generic storage clearing methods. Just make sure your Chrome version supports this CDP domain. It’s been stable since Chrome 72.

you could also launch with --incognito flag - no history gets saved so there’s nothing to clear. way easier than cdp commands imo, just throw it in your launch args and you’re set