Running headless browsers on Heroku with Rails and Unicorn configuration

I’m working on a Rails application deployed on Heroku using the Unicorn stack. I need to implement headless browser functionality for my app, possibly for testing or web scraping purposes.

I’ve come across several tutorials showing how to set up PhantomJS on Heroku’s Cedar stack by modifying the buildpack configuration. However, I’m specifically using the Unicorn stack for my Rails deployment.

Can anyone confirm if it’s feasible to integrate headless browser capabilities (like PhantomJS or similar tools) when running on Heroku’s Unicorn stack? Are there any special configuration steps or limitations I should be aware of? I want to make sure this setup will work before spending time on implementation.

the heroku stack dont matter here - unicorn, puma, whatever. they all handle headless browsers fine. pick the right tool and manage your resources well. chrome headless is your best option now that phantomjs support died. add the chrome buildpack and youre set. memory will bite u tho, so run fewer workers than normal.

Yeah, you can definitely run headless browsers on Heroku with Unicorn. I did this about 18 months ago for a Rails app that generated automated screenshots, though I took a different approach than what’s been mentioned. Unicorn’s master-worker setup actually plays nice with headless browsers if you configure it right. I used Chrome headless with the google-chrome buildpack, but here’s what really mattered: bump up Unicorn’s timeout settings and tweak the preload_app config. Headless operations take way longer than default timeouts, so workers get killed. I cranked my timeout up to 120 seconds and turned off preload_app to prevent shared browser instances between workers. For performance, spawning browsers on-demand worked better than keeping them persistent - Heroku’s memory limits don’t love that. Just watch your dyno metrics like a hawk when you first deploy.

I dealt with this exact thing two years ago when adding PDF generation to a Rails app on Heroku. Unicorn won’t block headless browsers, but there are some gotchas. First - skip PhantomJS, it’s basically dead. Go with Puppeteer or Selenium with Chrome headless. I used heroku-buildpack-google-chrome and heroku-buildpack-chromedriver buildpacks. Biggest issue is memory. Headless browsers eat RAM like crazy, and multiple Unicorn workers will slam you into Heroku’s limits fast. I had to cut my worker count and bump up to Standard-2X dynos for stable performance. Also - clean up your browser instances properly, especially in background jobs. Memory leaks will wreck your dynos.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.