puppeteer-bidi 0.0.1.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CLAUDE/README.md +158 -0
- data/CLAUDE/async_programming.md +158 -0
- data/CLAUDE/click_implementation.md +340 -0
- data/CLAUDE/core_layer_gotchas.md +136 -0
- data/CLAUDE/error_handling.md +232 -0
- data/CLAUDE/file_chooser.md +95 -0
- data/CLAUDE/frame_architecture.md +346 -0
- data/CLAUDE/javascript_evaluation.md +341 -0
- data/CLAUDE/jshandle_implementation.md +505 -0
- data/CLAUDE/keyboard_implementation.md +250 -0
- data/CLAUDE/mouse_implementation.md +140 -0
- data/CLAUDE/navigation_waiting.md +234 -0
- data/CLAUDE/porting_puppeteer.md +214 -0
- data/CLAUDE/query_handler.md +194 -0
- data/CLAUDE/rspec_pending_vs_skip.md +262 -0
- data/CLAUDE/selector_evaluation.md +198 -0
- data/CLAUDE/test_server_routes.md +263 -0
- data/CLAUDE/testing_strategy.md +236 -0
- data/CLAUDE/two_layer_architecture.md +180 -0
- data/CLAUDE/wrapped_element_click.md +247 -0
- data/CLAUDE.md +185 -0
- data/LICENSE.txt +21 -0
- data/README.md +488 -0
- data/Rakefile +21 -0
- data/lib/puppeteer/bidi/async_utils.rb +151 -0
- data/lib/puppeteer/bidi/browser.rb +285 -0
- data/lib/puppeteer/bidi/browser_context.rb +53 -0
- data/lib/puppeteer/bidi/browser_launcher.rb +240 -0
- data/lib/puppeteer/bidi/connection.rb +182 -0
- data/lib/puppeteer/bidi/core/README.md +169 -0
- data/lib/puppeteer/bidi/core/browser.rb +230 -0
- data/lib/puppeteer/bidi/core/browsing_context.rb +601 -0
- data/lib/puppeteer/bidi/core/disposable.rb +69 -0
- data/lib/puppeteer/bidi/core/errors.rb +64 -0
- data/lib/puppeteer/bidi/core/event_emitter.rb +83 -0
- data/lib/puppeteer/bidi/core/navigation.rb +128 -0
- data/lib/puppeteer/bidi/core/realm.rb +315 -0
- data/lib/puppeteer/bidi/core/request.rb +300 -0
- data/lib/puppeteer/bidi/core/session.rb +153 -0
- data/lib/puppeteer/bidi/core/user_context.rb +208 -0
- data/lib/puppeteer/bidi/core/user_prompt.rb +102 -0
- data/lib/puppeteer/bidi/core.rb +45 -0
- data/lib/puppeteer/bidi/deserializer.rb +132 -0
- data/lib/puppeteer/bidi/element_handle.rb +602 -0
- data/lib/puppeteer/bidi/errors.rb +42 -0
- data/lib/puppeteer/bidi/file_chooser.rb +52 -0
- data/lib/puppeteer/bidi/frame.rb +597 -0
- data/lib/puppeteer/bidi/http_response.rb +23 -0
- data/lib/puppeteer/bidi/injected.js +1 -0
- data/lib/puppeteer/bidi/injected_source.rb +21 -0
- data/lib/puppeteer/bidi/js_handle.rb +302 -0
- data/lib/puppeteer/bidi/keyboard.rb +265 -0
- data/lib/puppeteer/bidi/lazy_arg.rb +23 -0
- data/lib/puppeteer/bidi/mouse.rb +170 -0
- data/lib/puppeteer/bidi/page.rb +613 -0
- data/lib/puppeteer/bidi/query_handler.rb +397 -0
- data/lib/puppeteer/bidi/realm.rb +242 -0
- data/lib/puppeteer/bidi/serializer.rb +139 -0
- data/lib/puppeteer/bidi/target.rb +81 -0
- data/lib/puppeteer/bidi/task_manager.rb +44 -0
- data/lib/puppeteer/bidi/timeout_settings.rb +20 -0
- data/lib/puppeteer/bidi/transport.rb +129 -0
- data/lib/puppeteer/bidi/version.rb +7 -0
- data/lib/puppeteer/bidi/wait_task.rb +322 -0
- data/lib/puppeteer/bidi.rb +49 -0
- data/scripts/update_injected_source.rb +57 -0
- data/sig/puppeteer/bidi/browser.rbs +80 -0
- data/sig/puppeteer/bidi/element_handle.rbs +238 -0
- data/sig/puppeteer/bidi/frame.rbs +205 -0
- data/sig/puppeteer/bidi/js_handle.rbs +90 -0
- data/sig/puppeteer/bidi/page.rbs +247 -0
- data/sig/puppeteer/bidi.rbs +15 -0
- metadata +176 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Puppeteer
|
|
4
|
+
module Bidi
|
|
5
|
+
# Mouse class for mouse input operations
|
|
6
|
+
# Based on Puppeteer's BidiMouse implementation
|
|
7
|
+
class Mouse
|
|
8
|
+
# Mouse button constants
|
|
9
|
+
LEFT = 'left'
|
|
10
|
+
RIGHT = 'right'
|
|
11
|
+
MIDDLE = 'middle'
|
|
12
|
+
BACK = 'back'
|
|
13
|
+
FORWARD = 'forward'
|
|
14
|
+
|
|
15
|
+
def initialize(browsing_context)
|
|
16
|
+
@browsing_context = browsing_context
|
|
17
|
+
@x = 0
|
|
18
|
+
@y = 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Move mouse to coordinates
|
|
22
|
+
# @param x [Numeric] X coordinate
|
|
23
|
+
# @param y [Numeric] Y coordinate
|
|
24
|
+
# @param steps [Integer] Number of intermediate steps (for smooth movement)
|
|
25
|
+
def move(x, y, steps: 1)
|
|
26
|
+
from_x = @x
|
|
27
|
+
from_y = @y
|
|
28
|
+
|
|
29
|
+
@x = x
|
|
30
|
+
@y = y
|
|
31
|
+
|
|
32
|
+
actions = []
|
|
33
|
+
(1..steps).each do |step|
|
|
34
|
+
# Linear interpolation
|
|
35
|
+
intermediate_x = from_x + (x - from_x) * step / steps
|
|
36
|
+
intermediate_y = from_y + (y - from_y) * step / steps
|
|
37
|
+
|
|
38
|
+
actions << {
|
|
39
|
+
type: 'pointerMove',
|
|
40
|
+
x: intermediate_x.to_i,
|
|
41
|
+
y: intermediate_y.to_i
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
perform_actions(actions)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Press mouse button down
|
|
49
|
+
# @param button [String] Mouse button ('left', 'right', 'middle', 'back', 'forward')
|
|
50
|
+
def down(button: LEFT)
|
|
51
|
+
actions = [{
|
|
52
|
+
type: 'pointerDown',
|
|
53
|
+
button: button_to_bidi(button)
|
|
54
|
+
}]
|
|
55
|
+
perform_actions(actions)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Release mouse button
|
|
59
|
+
# @param button [String] Mouse button
|
|
60
|
+
def up(button: LEFT)
|
|
61
|
+
actions = [{
|
|
62
|
+
type: 'pointerUp',
|
|
63
|
+
button: button_to_bidi(button)
|
|
64
|
+
}]
|
|
65
|
+
perform_actions(actions)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Click at coordinates
|
|
69
|
+
# @param x [Numeric] X coordinate
|
|
70
|
+
# @param y [Numeric] Y coordinate
|
|
71
|
+
# @param button [String] Mouse button
|
|
72
|
+
# @param count [Integer] Number of clicks (1 for single, 2 for double, 3 for triple)
|
|
73
|
+
# @param delay [Numeric] Delay between down and up in milliseconds
|
|
74
|
+
def click(x, y, button: LEFT, count: 1, delay: nil)
|
|
75
|
+
actions = []
|
|
76
|
+
|
|
77
|
+
# Move to coordinates
|
|
78
|
+
if @x != x || @y != y
|
|
79
|
+
actions << {
|
|
80
|
+
type: 'pointerMove',
|
|
81
|
+
x: x.to_i,
|
|
82
|
+
y: y.to_i,
|
|
83
|
+
origin: 'viewport' # BiDi expects string, not hash
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
@x = x
|
|
88
|
+
@y = y
|
|
89
|
+
|
|
90
|
+
bidi_button = button_to_bidi(button)
|
|
91
|
+
|
|
92
|
+
# Perform clicks
|
|
93
|
+
count.times do
|
|
94
|
+
actions << {
|
|
95
|
+
type: 'pointerDown',
|
|
96
|
+
button: bidi_button
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if delay
|
|
100
|
+
actions << {
|
|
101
|
+
type: 'pause',
|
|
102
|
+
duration: delay.to_i
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
actions << {
|
|
107
|
+
type: 'pointerUp',
|
|
108
|
+
button: bidi_button
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
perform_actions(actions)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Scroll using mouse wheel
|
|
116
|
+
# @param delta_x [Numeric] Horizontal scroll amount
|
|
117
|
+
# @param delta_y [Numeric] Vertical scroll amount
|
|
118
|
+
def wheel(delta_x: 0, delta_y: 0)
|
|
119
|
+
@browsing_context.perform_actions([
|
|
120
|
+
{
|
|
121
|
+
type: 'wheel',
|
|
122
|
+
id: '__puppeteer_wheel',
|
|
123
|
+
actions: [
|
|
124
|
+
{
|
|
125
|
+
type: 'scroll',
|
|
126
|
+
x: @x.to_i,
|
|
127
|
+
y: @y.to_i,
|
|
128
|
+
deltaX: delta_x.to_i,
|
|
129
|
+
deltaY: delta_y.to_i
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
]).wait
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Reset mouse state
|
|
137
|
+
# Resets position to origin and releases all pressed buttons
|
|
138
|
+
def reset
|
|
139
|
+
@x = 0
|
|
140
|
+
@y = 0
|
|
141
|
+
@browsing_context.release_actions.wait
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
# Convert mouse button name to BiDi button number
|
|
147
|
+
def button_to_bidi(button)
|
|
148
|
+
case button
|
|
149
|
+
when LEFT then 0
|
|
150
|
+
when MIDDLE then 1
|
|
151
|
+
when RIGHT then 2
|
|
152
|
+
when BACK then 3
|
|
153
|
+
when FORWARD then 4
|
|
154
|
+
else 0
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Perform input actions via BiDi
|
|
159
|
+
def perform_actions(action_list)
|
|
160
|
+
@browsing_context.perform_actions([
|
|
161
|
+
{
|
|
162
|
+
type: 'pointer',
|
|
163
|
+
id: 'default mouse',
|
|
164
|
+
actions: action_list
|
|
165
|
+
}
|
|
166
|
+
]).wait
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|