Recently, while working on automating the installation and setup of my computer I encountered an annoying situation. I was trying to script out the installation of Dropbox, and I didn’t want to hard code in an installer version - for all other tools and applications that I “manually” install with scripts I’ve been able to obtain explicit version information programmatically. For some I could get version information via dedicated webpages (e.g.
golang which provides its current version here). For others, which host their release assets on GitHub I could use the GitHub Releases API (e.g. the
starship shell prompt, which uses GitHub Releases). In fact, up until Dropbox, the only tool which made this even a little difficult was the
aws-cli which required that I parse their CHANGELOG file to figure out the latest version.
As annoying as this was, I didn’t just settle for hard coding in the version for this one thing, and instead I looked around for a CLI wrapper for either Playwright or Puppeteer which are tools I’ve used extensively before to do browser automation via headless chromium, firefox, and webkit. Either of these would make it possible for me to visit the page, render the page with JS, then get the final page HTML. As it turns out, Playwright does have a first-party CLI, but amazingly to me, it’s mostly geared towards PDF creation and automation of writing Playwright procedures - not prerendering…this seems like super low hanging fruit, but ahhhh well.
Aaaanyway, I decided just to make my own wrapper for Playwright, so here it is!
PWPR - The simple Playwright Pre-Render CLI 🎉
You can find it on NPM at https://www.npmjs.com/package/pwpr. You don’t need to install it to use it (in fact, I don’t recommend that you do install it) - simply run:
npx pwpr --url=example.com --output=example.html
doing this will fetch
example.html in your current working directory - it’s like the simplicity of cURL, but with the ability to run the JS of the page you’re fetching.
Of course, the source code is fully open source and
MITlicensed, so check that out on GitHub —> andrewbrey/pwpr
With this, I’ve been able to keep my Dropbox install simple and programmatic, without any version hard coding. Hopefully someone else out there finds it useful!