Using puppeteer in a Rails 7.2.1 application with external browserless Chrome container connection with Puppeteer.connect(..) do |browser| .. end. Memory usage slowly creeps up. When built into a Docker image, any hard limit will eventually be hit despite the ruby VM trying to garbage collect. I am "ensure"ing a browser.close and browser.disconnect within the block. Here's the exact block...
Puppeteer.connect(browser_ws_endpoint: ENV['WEBSOCKET_CHROME_URL']) do |browser|
Rails.logger.debug "Attempting to capture screenshot of: + #{uri}"
begin
page = browser.new_page
page.viewport = Puppeteer::Viewport.new(width: 1280, height: 1280)
page.goto(uri.to_s, timeout: 5000) # , wait_until: 'domcontentloaded')
self.http_screenshot = page.screenshot
rescue StandardError => e
# Errors can be thrown due to a number of things: DNS, timeout, etc.
Rails.logger.debug 'Failed to capture screenshot.'
Rails.logger.debug e
ensure
Rails.logger.debug 'Closing browser.'
browser.close
browser.disconnect
end
end
Step To Reproduce / Observed behavior
Using puppeteer in a Rails 7.2.1 application with external browserless Chrome container connection with
Puppeteer.connect(..) do |browser| .. end
. Memory usage slowly creeps up. When built into a Docker image, any hard limit will eventually be hit despite the ruby VM trying to garbage collect. I am "ensure"ing a browser.close and browser.disconnect within the block. Here's the exact block...Expected behavior
Memory to remain fairly stable.
Environment
macOS with rvm
Paste the output of
ruby --version
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23]