Skip to content

Best way to block on chrome loading #185

@professor

Description

@professor

This is a follow on question from the discussion in #122, in the discussion, there's a great recommendation:

If request is to external server try to block such if it's not vital part of your app

However, it is not clear to me what is the best way to do this. At first, I added helper methods that looked at each frame to make sure that it was done loading. For one of my pages, this is sufficient and I never have a pending connections errors. However, on another page that I'm loading, this often isn't enough. I think it's still downloading images. At first, I put a sleep 10 but have had to slowly grow it to sleep 40

Is there a better API to ask ferrum if my code should keep waiting?

def done_loading(browser)
  states = browser.frames.collect do |frame|
    frame.state
  end
  states = states.uniq
  states == [:stopped_loading]
end

def wait_for_done_loading(browser)
  while !done_loading(browser)
    sleep 1
  end
  sleep 2 #allows javascript to "settle down"
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions