Class: AutoBrowse::CupriteBrowser
- Defined in:
- lib/auto_browse/browser.rb
Class Method Summary collapse
Instance Method Summary collapse
- #driver ⇒ Object
- #goto(url) ⇒ Object
-
#initialize ⇒ CupriteBrowser
constructor
A new instance of CupriteBrowser.
- #mouse ⇒ Object
- #move(x, y) ⇒ Object
- #new_window ⇒ Object
- #quit ⇒ Object
- #switch_to_window(window) ⇒ Object
- #visit(url) ⇒ Object
- #windows ⇒ Object
Methods inherited from Browser
#execute_script, #set_default_timeout
Constructor Details
#initialize ⇒ CupriteBrowser
Returns a new instance of CupriteBrowser.
88 89 90 91 |
# File 'lib/auto_browse/browser.rb', line 88 def initialize @session = ::Session.new(:cuprite) @windows = [@session.current_window] end |
Class Method Details
.register ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/auto_browse/browser.rb', line 40 def self.register .javascript_driver = :cuprite .register_driver(:cuprite) do |app| # the list of command line flags is enormous: https://peter.sh/experiments/chromium-command-line-switches/ = { # "hide-scrollbars" => nil, # "mute-audio" => nil, # "enable-automation" => nil, "disable-web-security" => nil, # "disable-session-crashed-bubble" => nil, "disable-breakpad" => nil, # "disable-sync" => nil, "no-first-run" => nil, "use-mock-keychain" => nil, # "keep-alive-for-test" => nil, # "disable-popup-blocking" => nil, # "disable-extensions" => nil, "disable-hang-monitor" => nil, "disable-features" => "site-per-process,TranslateUI", # "disable-translate" => nil, # "disable-background-networking" => nil, "enable-features" => "NetworkService,NetworkServiceInProcess", # "disable-background-timer-throttling" => nil, # "disable-backgrounding-occluded-windows" => nil, # "disable-client-side-phishing-detection" => nil, # "disable-default-apps" => nil, "disable-dev-shm-usage" => nil, # "disable-ipc-flooding-protection" => nil, # "disable-prompt-on-repost" => nil, # "disable-renderer-backgrounding" => nil, # "force-color-profile" => "srgb", "metrics-recording-only" => nil, # "safebrowsing-disable-auto-update" => nil, "password-store" => "basic" } .merge!(headless: nil) if ENV["HEADLESS"] == "true" = { window_size: [1440, 900], # headless: ENV["HEADLESS"] == "true", # has no effect ignore_default_browser_options: true, browser_options: } ::Cuprite::Driver.new(app, ) end end |
.set_global_default_timeout(timeout = 30) ⇒ Object
36 37 38 |
# File 'lib/auto_browse/browser.rb', line 36 def self.set_global_default_timeout(timeout = 30) .default_max_wait_time = timeout end |
Instance Method Details
#driver ⇒ Object
93 94 95 |
# File 'lib/auto_browse/browser.rb', line 93 def driver @session end |
#goto(url) ⇒ Object
106 107 108 |
# File 'lib/auto_browse/browser.rb', line 106 def goto(url) @session.visit(url) end |
#mouse ⇒ Object
97 98 99 |
# File 'lib/auto_browse/browser.rb', line 97 def mouse @session.driver.browser.mouse end |
#move(x, y) ⇒ Object
101 102 103 104 |
# File 'lib/auto_browse/browser.rb', line 101 def move(x, y) mouse.move(x: x, y: y) sleep 0.01 end |
#new_window ⇒ Object
114 115 116 117 118 |
# File 'lib/auto_browse/browser.rb', line 114 def new_window window = @session.open_new_window @windows << window window end |
#quit ⇒ Object
128 129 130 |
# File 'lib/auto_browse/browser.rb', line 128 def quit @session.quit end |
#switch_to_window(window) ⇒ Object
120 121 122 |
# File 'lib/auto_browse/browser.rb', line 120 def switch_to_window(window) @session.switch_to_window(window) end |
#visit(url) ⇒ Object
110 111 112 |
# File 'lib/auto_browse/browser.rb', line 110 def visit(url) goto(url) end |
#windows ⇒ Object
124 125 126 |
# File 'lib/auto_browse/browser.rb', line 124 def windows @windows end |