Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME when rendering jstree with with capybara and headless chrome

Viewed 2524

Recently I switched to headless chrome in my rspec tests. After the move all my tests which interact with jstree element started to fail. Below is the smallest code which allow to reproduce the bug:

There are dependencies in the Gemfile:

# Gemfile
gem 'capybara', '2.18.0'
gem 'selenium-webdriver', '3.141.0'

It is the simple page which renders jstree:

# jstree.html

<!doctype html>
<html>
  <head>
    <script src="https://rawgit.com/jquery/jquery/1.12.4/dist/jquery.min.js"></script>
    <script src="https://rawgit.com/vakata/jstree/3.3.7/dist/jstree.min.js"></script>
    <link href="https://rawgit.com/vakata/jstree/3.3.7/dist/themes/default/style.min.css" rel="stylesheet"/>
  </head>

  <body>
    <h1>This is a list:</h1>
    <ul id="tree"></ul>
    <script>
      $('#tree').jstree({
        core: {
          data: [{ "id": 1, "state": {}, "text": "Example", "parent": "#" }]
        }
      });
    </script>
  </body>
</html>

There is a ruby script to open the page with Capybara and save page screenshot:

# script.rb
require 'capybara'

require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new(
    args: %w[headless no-sandbox disable-dev-shm-usage window-size=1280,800])

  Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.default_driver = :chrome
Capybara.app = Rack::File.new File.expand_path('../', __FILE__)

include Capybara::DSL
visit '/jstree.html'
page.save_and_open_screenshot

When I run bundle exec ruby script.rb and then open the screenshot I see the following:

enter image description here

but when I open jstree.html in my chrome browser I see normal tree:

enter image description here

When I add output browser console messages to the end of the script

puts page.driver.browser.manage.logs.get(type)

and rerun bundle exec ruby script.rb I get

SEVERE 2018-12-27 16:24:23 +0300: blob:http://127.0.0.1:49346/26695642-8b26-494b-a142-54a515db6512 - Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME

I am using chrome v71 and chromedriver v2.45

Does anybody have any idea what is going on there? How can I fix this issue?

1 Answers

Unfortunately Chrome 71 broke blob URLs in headless mode. If you run against the Chrome 72 beta it should be fixed. You can see a discussion in a puppeteer issue - https://github.com/GoogleChrome/puppeteer/issues/3463

Also note you don't need to use the capybara-screenshot gem to take that screenshot - just call page.save_and_open_screenshot

Related