Module: Browsed::Browser
- Included in:
- Client
- Defined in:
- lib/browsed/browser.rb
Instance Method Summary collapse
- #generate_browser_id ⇒ Object
- #is_ipad? ⇒ Boolean
- #is_iphone? ⇒ Boolean
- #randomize_ios_resolution ⇒ Object
- #randomize_resolution ⇒ Object
- #resizable_browser? ⇒ Boolean
-
#resize!(res = nil) ⇒ Object
Resize the window separately and not based on initialization.
- #runs_ios? ⇒ Boolean
-
#set_resolution(res) ⇒ Object
Resolution.
-
#set_user_agent(user_agent) ⇒ Object
User Agents.
Instance Method Details
#generate_browser_id ⇒ Object
4 5 6 |
# File 'lib/browsed/browser.rb', line 4 def generate_browser_id SecureRandom.hex end |
#is_ipad? ⇒ Boolean
50 51 52 |
# File 'lib/browsed/browser.rb', line 50 def is_ipad? Agents.is_ipad?(self.user_agent) end |
#is_iphone? ⇒ Boolean
46 47 48 |
# File 'lib/browsed/browser.rb', line 46 def is_iphone? Agents.is_iphone?(self.user_agent) end |
#randomize_ios_resolution ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/browsed/browser.rb', line 67 def randomize_ios_resolution resolution_device = case self.device when :iphone, :android_phone :phone when :ipad, :android_tablet :tablet else self.device end random_key = Browsed::Constants::RESOLUTIONS.fetch(resolution_device, :desktop).keys.sample resolution = Browsed::Constants::RESOLUTIONS.fetch(resolution_device, :desktop)[random_key] end |
#randomize_resolution ⇒ Object
63 64 65 |
# File 'lib/browsed/browser.rb', line 63 def randomize_resolution runs_ios? ? randomize_ios_resolution : Browsed::Constants::RESOLUTIONS.fetch(self.device, :desktop).sample end |
#resizable_browser? ⇒ Boolean
17 18 19 20 |
# File 'lib/browsed/browser.rb', line 17 def resizable_browser? non_resizable = [:poltergeist, :selenium_chrome, :selenium_chrome_headless] !non_resizable.include?(self.driver.to_sym) end |
#resize!(res = nil) ⇒ Object
Resize the window separately and not based on initialization
9 10 11 12 13 14 15 |
# File 'lib/browsed/browser.rb', line 9 def resize!(res = nil) res ||= self.resolution if self.session && res && res.size.eql?(2) && resizable_browser? # Resolutions for Chrome & Poltergeist are set in the driver self.session&.current_window&.resize_to(res.first, res.last) # [width, height] end end |
#runs_ios? ⇒ Boolean
42 43 44 |
# File 'lib/browsed/browser.rb', line 42 def runs_ios? Agents.runs_ios?(self.user_agent) end |
#set_resolution(res) ⇒ Object
Resolution
55 56 57 58 59 60 61 |
# File 'lib/browsed/browser.rb', line 55 def set_resolution(res) if res && res.is_a?(Array) self.resolution = res elsif res && res.is_a?(Symbol) && res.eql?(:randomize) self.resolution = randomize_resolution end end |
#set_user_agent(user_agent) ⇒ Object
User Agents
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/browsed/browser.rb', line 23 def set_user_agent(user_agent) if !user_agent.to_s.empty? && !user_agent.to_sym.eql?(:randomize) self.user_agent = user_agent elsif (!user_agent.to_s.empty? && user_agent.to_sym.eql?(:randomize)) || phantomjs? case self.device when :iphone self.user_agent = Agents.random_user_agent(:phones, :iphone) when :android_phone self.user_agent = Agents.random_user_agent(:phones, :android) when :ipad self.user_agent = Agents.random_user_agent(:tablets, :ipad) when :android_tablet self.user_agent = Agents.random_user_agent(:tablets, :android) else self.user_agent = Agents.random_user_agent(self.device) end end end |