Last week, I wrote about a cool new API in Bun called WebView that makes it possible to open a URL in a headless browser without needing something like Puppeteer or Playwright. The code looks like this:
import { WebView } from "bun"
await using view = new WebView({ width: 2000, height: 3000 })
await view.navigate(url)
// example, evaluate JavaScript
console.log(await view.evaluate("document.body.innerHTML"))
// example, take a screenshot
const png = await view.screenshot()
await Bun.write(values.screenshot, png)
However, there's a drawback: each time I run a process like this on my Ubuntu 20.04 server, it creates directories such as /tmp/snap-private-tmp/snap.chromium/tmp/bun-chrome-80856 and /tmp/snap-private-tmp/snap.chromium/tmp/org.chromium.Chromium.YL1S7L.
After I've run the above Bun code five times, I see this:
root@ubuntu-s-2vcpu-8gb-amd-nyc3-01:~# ls -l /tmp/snap-private-tmp/snap.chromium/tmp/ total 0 drwx------ 31 django django 740 Apr 29 12:30 bun-chrome-80651 drwx------ 31 django django 740 Apr 29 12:30 bun-chrome-80856 drwx------ 31 django django 740 Apr 29 12:30 bun-chrome-81058 drwx------ 31 django django 740 Apr 29 12:30 bun-chrome-81260 drwx------ 31 django django 740 Apr 29 12:30 bun-chrome-81459 drwx------ 2 django django 80 Apr 29 12:30 org.chromium.Chromium.3zCHrv drwx------ 2 django django 80 Apr 29 12:30 org.chromium.Chromium.ImIP4v drwx------ 2 django django 80 Apr 29 12:30 org.chromium.Chromium.YL1S7L drwx------ 2 django django 80 Apr 29 12:30 org.chromium.Chromium.erkDSy drwx------ 2 django django 80 Apr 29 12:30 org.chromium.Chromium.orhmkv
They're pretty big too.
# du -sh /tmp/snap-private-tmp/snap.chromium/tmp/bun-chrome-80651/ 4.0M /tmp/snap-private-tmp/snap.chromium/tmp/bun-chrome-80651/ # du -sh /tmp/snap-private-tmp/snap.chromium/tmp/ 21M /tmp/snap-private-tmp/snap.chromium/tmp/
Here, that bun-chrome-80651 was "only" 4MB. If you open a more busy web site, I've seen it become around 25MB.
I learned this the hard way because I server nearly died from exhausted disk usage since that directory was taking up ~4GB.
Now I have bash cron script that periodically deletes these files.
Comments