How to hide chat widgets when taking a screenshot with Puppeteer

When you want to take chat widgets, there are annoying chat widgets that you would love to hide. It is easy to do.

Written by

Dmytro Krasun

Published on

All you need is to detect the selector of the chat container and then apply display: none !important to it.

Let’s look, for example, with Crisp chat on ScreenshotOne main page:

The ScreenshotOne site with a chat widget

To hide it, find the selector of the main container of the chat. You can do it by using Chrome DevTools:

The ScreenshotOne site with Chrome DevTools

And then add the hiding styling before taking a screenshot:

const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true });
try {
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 1024 });
await page.goto('https://screenshotone.com/', { waitUntil: ['load', 'domcontentloaded', 'networkidle0'] });
await page.addStyleTag({
content: '.crisp-client { display: none !important; }',
});
await page.screenshot({ type: 'png', path: 'screenshot.png' });
} catch (e) {
console.log(e)
} finally {
await browser.close();
}
})();

And voila:

The ScreenshotOne site without the chat widget

If you take screenshots at scale, you need to do this for every chat widget. Or you can use [ScreenshotOne API] that knows how to hide Facebook Messenger, Tawk, Crisp, Intercom, Drift, and many more.

Have a nice day 👋 and you also might find helpful:

Read more Puppeteer guides

Interviews, tips, guides, industry best practices, and news.

View all posts
How to create a site thumbnail with Puppeteer

How to create a site thumbnail with Puppeteer

We can consider the screenshot of URL or HTML as a thumbnail, but I write about the thumbnail of a screenshot. How do you take a screenshot within the defined viewport but with different image width and height? Resize!

Read more
How to take website screenshots in Python

How to take website screenshots in Python

With Python, you can take website screenshots in multiple ways. But the best way to do it depends solely on your needs and your use case. Let's quickly examine all the options.

Read more

Automate website screenshots

Exhaustive documentation, ready SDKs, no-code tools, and other automation to help you render website screenshots and outsource all the boring work related to that to us.