Search code examples
rubyheadless

Headless Browser in ruby, non testing purpose


What are the options for using Headless browser in ruby? Already Tried Watir, but it opens a browser window for every page opened, that is un desired side effect. It would be awesome if there was something like Phanthom JS or if i could Phanthom JS in ruby code.


Solution

  • First, Watir does not "open a browser window for every page" as you describe, unless you are doing something wrong.

    Second, you can use phantomjs with Watir. Uninstall the Headless gem, and just do

    broswer = Watir::Browser.new :phantomjs
    
    browser.goto "some_web_page.com"
    
    browser.close  # When you are done.
    

    I suspect you are opening a new browser instance for every page, rather than just using goto. If that's the case, try using .new() or .start() just once, then .goto() after that. That is, just replace :phantomjs in the code above with :ff for example.

    Keep in mind that if you use "headless", last I heard it did not yet work on OS X.