Class: Charai::BrowsingContext

Inherits:
Object
  • Object
show all
Defined in:
lib/charai/browsing_context.rb

Defined Under Namespace

Classes: Realm

Instance Method Summary collapse

Constructor Details

#initialize(browser, context_id) ⇒ BrowsingContext

Returns a new instance of BrowsingContext.



5
6
7
8
# File 'lib/charai/browsing_context.rb', line 5

def initialize(browser, context_id)
  @browser = browser
  @context_id = context_id
end

Instance Method Details

#_update_url(url) ⇒ Object



110
111
112
# File 'lib/charai/browsing_context.rb', line 110

def _update_url(url)
  @url = url
end

#activateObject



33
34
35
# File 'lib/charai/browsing_context.rb', line 33

def activate
  bidi_call_async('browsingContext.activate').value!
end

#capture_screenshot(origin: nil, format: nil, clip: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/charai/browsing_context.rb', line 37

def capture_screenshot(origin: nil, format: nil, clip: nil)
  result = bidi_call_async('browsingContext.captureScreenshot', {
    origin: origin,
    format: format,
    clip: clip,
  }.compact).value!

  Base64.strict_decode64(result['data'])
end

#close(prompt_unload: nil) ⇒ Object



47
48
49
50
51
# File 'lib/charai/browsing_context.rb', line 47

def close(prompt_unload: nil)
  bidi_call_async('browsingContext.close', {
    promptUnload: prompt_unload,
  }.compact).value!
end

#default_realmObject



29
30
31
# File 'lib/charai/browsing_context.rb', line 29

def default_realm
  realms.find { |realm| realm.type == 'window' }
end


10
11
12
13
14
15
# File 'lib/charai/browsing_context.rb', line 10

def navigate(url, wait: :interactive)
  bidi_call_async('browsingContext.navigate', {
    url: url,
    wait: wait,
  }.compact).value!
end

#perform_keyboard_actions(&block) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/charai/browsing_context.rb', line 53

def perform_keyboard_actions(&block)
  q = ActionQueue.new
  block.call(q)
  perform_actions([{
    type: 'key',
    id: '__charai_keyboard',
    actions: q.to_a,
  }])
end

#perform_mouse_actions(&block) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/charai/browsing_context.rb', line 63

def perform_mouse_actions(&block)
  q = ActionQueue.new
  block.call(q)
  perform_actions([{
    type: 'pointer',
    id: '__charai_mouse',
    actions: q.to_a,
  }])
end

#perform_mouse_wheel_actions(&block) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/charai/browsing_context.rb', line 73

def perform_mouse_wheel_actions(&block)
  q = ActionQueue.new
  block.call(q)
  perform_actions([{
    type: 'wheel',
    id: '__charai_wheel',
    actions: q.to_a,
  }])
end

#realmsObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/charai/browsing_context.rb', line 17

def realms
  result = bidi_call_async('script.getRealms').value!
  result['realms'].map do |realm|
    Realm.new(
      browsing_context: self,
      id: realm['realm'],
      origin: realm['origin'],
      type: realm['type'],
    )
  end
end

#reload(ignore_cache: nil, wait: nil) ⇒ Object



83
84
85
86
87
88
# File 'lib/charai/browsing_context.rb', line 83

def reload(ignore_cache: nil, wait: nil)
  bidi_call_async('browsingContext.reload', {
    ignoreCache: ignore_cache,
    wait: wait,
  }.compact).value!
end

#set_viewport(width:, height:, device_pixel_ratio: nil) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/charai/browsing_context.rb', line 90

def set_viewport(width:, height:, device_pixel_ratio: nil)
  bidi_call_async('browsingContext.setViewport', {
    viewport: {
      width: width,
      height: height,
    },
    devicePixelRatio: device_pixel_ratio,
  }.compact).value!
end

#traverse_history(delta) ⇒ Object



100
101
102
103
104
# File 'lib/charai/browsing_context.rb', line 100

def traverse_history(delta)
  bidi_call_async('browsingContext.traverseHistory', {
    delta: delta,
  }).value!
end

#urlObject



106
107
108
# File 'lib/charai/browsing_context.rb', line 106

def url
  @url
end