YusukeIwaki/puppeteer-ruby

Rails one action how to screenshot another action's render?

gamesover opened this issue · 1 comments

Step To Reproduce / Observed behavior

I have one ruby on rails action, puppeteer-ruby will run inside one action to screenshot another action's render.

It throws out error

Puppeteer::FrameManager::NavigationError (Navigation timeout of 30000ms exceeded):

example code

class ExampleController < ApiController
  def action_a
     # render template here
  end
 
   def action_b
       Puppeteer.launch(headless: false) do |browser|
          page = browser.new_page
          url = "http://localhost:3000/action_a"
          page.goto(url) # throw Puppeteer::FrameManager::NavigationError
          page.screenshot(path: "YusukeIwaki.png")
        end
   end
end

Expected behavior

successfully screenshot the render from the same server

found the solution. It is needed to be wrapped within Thread.new

such as

def action_b
  Thread.new do
       Puppeteer.launch(headless: false) do |browser|
          page = browser.new_page
          url = "http://localhost:3000/action_a"
          page.goto(url) # throw Puppeteer::FrameManager::NavigationError
          page.screenshot(path: "YusukeIwaki.png")
        end
  end
 end