ferrum
ferrum copied to clipboard
`Emulation.setEmulatedMedia` not working?
Hello!
I'm trying to use the Emulation.setEmulatedMedia query to set the media query to print, but I get the error:
'Emulation.setEmulatedMedia' wasn't found (Ferrum::BrowserError)
Here is a single file reproduction of the problem:
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "ferrum"
end
browser = Ferrum::Browser.new
browser.command("Emulation.setEmulatedMedia", media: "print")
browser.go_to("https://lachy.id.au/dev/css/tests/media/print/html401-print.html")
% ruby test.rb
/Users/me/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/ferrum-0.13/lib/ferrum/browser/client.rb:97:in `raise_browser_error': 'Emulation.setEmulatedMedia' wasn't found (Ferrum::BrowserError)
from /Users/me/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/ferrum-0.13/lib/ferrum/browser/client.rb:49:in `command'
from /Users/me/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/ferrum-0.13/lib/ferrum/browser.rb:209:in `command'
from test.rb:10:in `<main>'
I'm not entirely sure where the issue lies here, apologies if the root cause is actually somewhere down the line.
This is an old issue but setEmulatedMedia appears to be a page-level command, not a browser command. To command the page you have to call browser.page.command instead.
As an example for prefers-reduced-motion:
browser.page.command('Emulation.setEmulatedMedia', features: [{name: 'prefers-reduced-motion', value: 'reduce'}])