- Clone this repository:
git clone https://github.com/strarsis/screenshot-with-transparent-background - (cwd into it)
cd screenshot-with-transparent-background - (optional) Install + use node LTS version using
nvm:nvm install && nvm use - Install node dependencies:
npm install - Invoke the script:
node index.js# example defaults (sample page toscreenshot.png).node index.js https://www.example.com output.png
The script uses the chromium engine.
Playwright also supports Webkit and Firefox.
The engine to be used can be modified easily, just replace chromium with webkit or firefox.
Taking a screenshot with transparent background of a web page only works of course when that web page does not epxlicitly use a background (and when it is just white) on its html, body or other page-covering elements.
If you still want to have a transparent background, you need to modify the styles of the page and remove the background or make it transparent.
You would add the code that modifies the page before taking the screenshot to the takeScreenshot() before page.screenshot(), see the commented out pre-process example in the script.