input.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. // Package input provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Input domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package input
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. )
  11. // DispatchDragEventParams dispatches a drag event into the page.
  12. type DispatchDragEventParams struct {
  13. Type DispatchDragEventType `json:"type"` // Type of the drag event.
  14. X float64 `json:"x"` // X coordinate of the event relative to the main frame's viewport in CSS pixels.
  15. Y float64 `json:"y"` // Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  16. Data *DragData `json:"data"`
  17. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  18. }
  19. // DispatchDragEvent dispatches a drag event into the page.
  20. //
  21. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchDragEvent
  22. //
  23. // parameters:
  24. //
  25. // type - Type of the drag event.
  26. // x - X coordinate of the event relative to the main frame's viewport in CSS pixels.
  27. // y - Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  28. // data
  29. func DispatchDragEvent(typeVal DispatchDragEventType, x float64, y float64, data *DragData) *DispatchDragEventParams {
  30. return &DispatchDragEventParams{
  31. Type: typeVal,
  32. X: x,
  33. Y: y,
  34. Data: data,
  35. }
  36. }
  37. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  38. // Meta/Command=4, Shift=8 (default: 0).
  39. func (p DispatchDragEventParams) WithModifiers(modifiers Modifier) *DispatchDragEventParams {
  40. p.Modifiers = modifiers
  41. return &p
  42. }
  43. // Do executes Input.dispatchDragEvent against the provided context.
  44. func (p *DispatchDragEventParams) Do(ctx context.Context) (err error) {
  45. return cdp.Execute(ctx, CommandDispatchDragEvent, p, nil)
  46. }
  47. // DispatchKeyEventParams dispatches a key event to the page.
  48. type DispatchKeyEventParams struct {
  49. Type KeyType `json:"type"` // Type of the key event.
  50. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  51. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty"` // Time at which the event occurred.
  52. Text string `json:"text,omitempty"` // Text as generated by processing a virtual key code with a keyboard layout. Not needed for for keyUp and rawKeyDown events (default: "")
  53. UnmodifiedText string `json:"unmodifiedText,omitempty"` // Text that would have been generated by the keyboard if no modifiers were pressed (except for shift). Useful for shortcut (accelerator) key handling (default: "").
  54. KeyIdentifier string `json:"keyIdentifier,omitempty"` // Unique key identifier (e.g., 'U+0041') (default: "").
  55. Code string `json:"code,omitempty"` // Unique DOM defined string value for each physical key (e.g., 'KeyA') (default: "").
  56. Key string `json:"key,omitempty"` // Unique DOM defined string value describing the meaning of the key in the context of active modifiers, keyboard layout, etc (e.g., 'AltGr') (default: "").
  57. WindowsVirtualKeyCode int64 `json:"windowsVirtualKeyCode,omitempty"` // Windows virtual key code (default: 0).
  58. NativeVirtualKeyCode int64 `json:"nativeVirtualKeyCode,omitempty"` // Native virtual key code (default: 0).
  59. AutoRepeat bool `json:"autoRepeat"` // Whether the event was generated from auto repeat (default: false).
  60. IsKeypad bool `json:"isKeypad"` // Whether the event was generated from the keypad (default: false).
  61. IsSystemKey bool `json:"isSystemKey"` // Whether the event was a system key event (default: false).
  62. Location int64 `json:"location,omitempty"` // Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default: 0).
  63. Commands []string `json:"commands,omitempty"` // Editing commands to send with the key event (e.g., 'selectAll') (default: []). These are related to but not equal the command names used in document.execCommand and NSStandardKeyBindingResponding. See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h for valid command names.
  64. }
  65. // DispatchKeyEvent dispatches a key event to the page.
  66. //
  67. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchKeyEvent
  68. //
  69. // parameters:
  70. //
  71. // type - Type of the key event.
  72. func DispatchKeyEvent(typeVal KeyType) *DispatchKeyEventParams {
  73. return &DispatchKeyEventParams{
  74. Type: typeVal,
  75. }
  76. }
  77. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  78. // Meta/Command=4, Shift=8 (default: 0).
  79. func (p DispatchKeyEventParams) WithModifiers(modifiers Modifier) *DispatchKeyEventParams {
  80. p.Modifiers = modifiers
  81. return &p
  82. }
  83. // WithTimestamp time at which the event occurred.
  84. func (p DispatchKeyEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *DispatchKeyEventParams {
  85. p.Timestamp = timestamp
  86. return &p
  87. }
  88. // WithText text as generated by processing a virtual key code with a
  89. // keyboard layout. Not needed for for keyUp and rawKeyDown events (default:
  90. // "").
  91. func (p DispatchKeyEventParams) WithText(text string) *DispatchKeyEventParams {
  92. p.Text = text
  93. return &p
  94. }
  95. // WithUnmodifiedText text that would have been generated by the keyboard if
  96. // no modifiers were pressed (except for shift). Useful for shortcut
  97. // (accelerator) key handling (default: "").
  98. func (p DispatchKeyEventParams) WithUnmodifiedText(unmodifiedText string) *DispatchKeyEventParams {
  99. p.UnmodifiedText = unmodifiedText
  100. return &p
  101. }
  102. // WithKeyIdentifier unique key identifier (e.g., 'U+0041') (default: "").
  103. func (p DispatchKeyEventParams) WithKeyIdentifier(keyIdentifier string) *DispatchKeyEventParams {
  104. p.KeyIdentifier = keyIdentifier
  105. return &p
  106. }
  107. // WithCode unique DOM defined string value for each physical key (e.g.,
  108. // 'KeyA') (default: "").
  109. func (p DispatchKeyEventParams) WithCode(code string) *DispatchKeyEventParams {
  110. p.Code = code
  111. return &p
  112. }
  113. // WithKey unique DOM defined string value describing the meaning of the key
  114. // in the context of active modifiers, keyboard layout, etc (e.g., 'AltGr')
  115. // (default: "").
  116. func (p DispatchKeyEventParams) WithKey(key string) *DispatchKeyEventParams {
  117. p.Key = key
  118. return &p
  119. }
  120. // WithWindowsVirtualKeyCode windows virtual key code (default: 0).
  121. func (p DispatchKeyEventParams) WithWindowsVirtualKeyCode(windowsVirtualKeyCode int64) *DispatchKeyEventParams {
  122. p.WindowsVirtualKeyCode = windowsVirtualKeyCode
  123. return &p
  124. }
  125. // WithNativeVirtualKeyCode native virtual key code (default: 0).
  126. func (p DispatchKeyEventParams) WithNativeVirtualKeyCode(nativeVirtualKeyCode int64) *DispatchKeyEventParams {
  127. p.NativeVirtualKeyCode = nativeVirtualKeyCode
  128. return &p
  129. }
  130. // WithAutoRepeat whether the event was generated from auto repeat (default:
  131. // false).
  132. func (p DispatchKeyEventParams) WithAutoRepeat(autoRepeat bool) *DispatchKeyEventParams {
  133. p.AutoRepeat = autoRepeat
  134. return &p
  135. }
  136. // WithIsKeypad whether the event was generated from the keypad (default:
  137. // false).
  138. func (p DispatchKeyEventParams) WithIsKeypad(isKeypad bool) *DispatchKeyEventParams {
  139. p.IsKeypad = isKeypad
  140. return &p
  141. }
  142. // WithIsSystemKey whether the event was a system key event (default: false).
  143. func (p DispatchKeyEventParams) WithIsSystemKey(isSystemKey bool) *DispatchKeyEventParams {
  144. p.IsSystemKey = isSystemKey
  145. return &p
  146. }
  147. // WithLocation whether the event was from the left or right side of the
  148. // keyboard. 1=Left, 2=Right (default: 0).
  149. func (p DispatchKeyEventParams) WithLocation(location int64) *DispatchKeyEventParams {
  150. p.Location = location
  151. return &p
  152. }
  153. // WithCommands editing commands to send with the key event (e.g.,
  154. // 'selectAll') (default: []). These are related to but not equal the command
  155. // names used in document.execCommand and NSStandardKeyBindingResponding. See
  156. // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h
  157. // for valid command names.
  158. func (p DispatchKeyEventParams) WithCommands(commands []string) *DispatchKeyEventParams {
  159. p.Commands = commands
  160. return &p
  161. }
  162. // Do executes Input.dispatchKeyEvent against the provided context.
  163. func (p *DispatchKeyEventParams) Do(ctx context.Context) (err error) {
  164. return cdp.Execute(ctx, CommandDispatchKeyEvent, p, nil)
  165. }
  166. // InsertTextParams this method emulates inserting text that doesn't come
  167. // from a key press, for example an emoji keyboard or an IME.
  168. type InsertTextParams struct {
  169. Text string `json:"text"` // The text to insert.
  170. }
  171. // InsertText this method emulates inserting text that doesn't come from a
  172. // key press, for example an emoji keyboard or an IME.
  173. //
  174. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-insertText
  175. //
  176. // parameters:
  177. //
  178. // text - The text to insert.
  179. func InsertText(text string) *InsertTextParams {
  180. return &InsertTextParams{
  181. Text: text,
  182. }
  183. }
  184. // Do executes Input.insertText against the provided context.
  185. func (p *InsertTextParams) Do(ctx context.Context) (err error) {
  186. return cdp.Execute(ctx, CommandInsertText, p, nil)
  187. }
  188. // ImeSetCompositionParams this method sets the current candidate text for
  189. // IME. Use imeCommitComposition to commit the final text. Use imeSetComposition
  190. // with empty string as text to cancel composition.
  191. type ImeSetCompositionParams struct {
  192. Text string `json:"text"` // The text to insert
  193. SelectionStart int64 `json:"selectionStart"` // selection start
  194. SelectionEnd int64 `json:"selectionEnd"` // selection end
  195. ReplacementStart int64 `json:"replacementStart,omitempty"` // replacement start
  196. ReplacementEnd int64 `json:"replacementEnd,omitempty"` // replacement end
  197. }
  198. // ImeSetComposition this method sets the current candidate text for IME. Use
  199. // imeCommitComposition to commit the final text. Use imeSetComposition with
  200. // empty string as text to cancel composition.
  201. //
  202. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-imeSetComposition
  203. //
  204. // parameters:
  205. //
  206. // text - The text to insert
  207. // selectionStart - selection start
  208. // selectionEnd - selection end
  209. func ImeSetComposition(text string, selectionStart int64, selectionEnd int64) *ImeSetCompositionParams {
  210. return &ImeSetCompositionParams{
  211. Text: text,
  212. SelectionStart: selectionStart,
  213. SelectionEnd: selectionEnd,
  214. }
  215. }
  216. // WithReplacementStart replacement start.
  217. func (p ImeSetCompositionParams) WithReplacementStart(replacementStart int64) *ImeSetCompositionParams {
  218. p.ReplacementStart = replacementStart
  219. return &p
  220. }
  221. // WithReplacementEnd replacement end.
  222. func (p ImeSetCompositionParams) WithReplacementEnd(replacementEnd int64) *ImeSetCompositionParams {
  223. p.ReplacementEnd = replacementEnd
  224. return &p
  225. }
  226. // Do executes Input.imeSetComposition against the provided context.
  227. func (p *ImeSetCompositionParams) Do(ctx context.Context) (err error) {
  228. return cdp.Execute(ctx, CommandImeSetComposition, p, nil)
  229. }
  230. // DispatchMouseEventParams dispatches a mouse event to the page.
  231. type DispatchMouseEventParams struct {
  232. Type MouseType `json:"type"` // Type of the mouse event.
  233. X float64 `json:"x"` // X coordinate of the event relative to the main frame's viewport in CSS pixels.
  234. Y float64 `json:"y"` // Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  235. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  236. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty"` // Time at which the event occurred.
  237. Button MouseButton `json:"button,omitempty"` // Mouse button (default: "none").
  238. Buttons int64 `json:"buttons,omitempty"` // A number indicating which buttons are pressed on the mouse when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
  239. ClickCount int64 `json:"clickCount,omitempty"` // Number of times the mouse button was clicked (default: 0).
  240. Force float64 `json:"force,omitempty"` // The normalized pressure, which has a range of [0,1] (default: 0).
  241. TangentialPressure float64 `json:"tangentialPressure,omitempty"` // The normalized tangential pressure, which has a range of [-1,1] (default: 0).
  242. TiltX float64 `json:"tiltX,omitempty"` // The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0).
  243. TiltY float64 `json:"tiltY,omitempty"` // The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0).
  244. Twist int64 `json:"twist,omitempty"` // The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0).
  245. DeltaX float64 `json:"deltaX"` // X delta in CSS pixels for mouse wheel event (default: 0).
  246. DeltaY float64 `json:"deltaY"` // Y delta in CSS pixels for mouse wheel event (default: 0).
  247. PointerType DispatchMouseEventPointerType `json:"pointerType,omitempty"` // Pointer type (default: "mouse").
  248. }
  249. // DispatchMouseEvent dispatches a mouse event to the page.
  250. //
  251. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchMouseEvent
  252. //
  253. // parameters:
  254. //
  255. // type - Type of the mouse event.
  256. // x - X coordinate of the event relative to the main frame's viewport in CSS pixels.
  257. // y - Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  258. func DispatchMouseEvent(typeVal MouseType, x float64, y float64) *DispatchMouseEventParams {
  259. return &DispatchMouseEventParams{
  260. Type: typeVal,
  261. X: x,
  262. Y: y,
  263. }
  264. }
  265. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  266. // Meta/Command=4, Shift=8 (default: 0).
  267. func (p DispatchMouseEventParams) WithModifiers(modifiers Modifier) *DispatchMouseEventParams {
  268. p.Modifiers = modifiers
  269. return &p
  270. }
  271. // WithTimestamp time at which the event occurred.
  272. func (p DispatchMouseEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *DispatchMouseEventParams {
  273. p.Timestamp = timestamp
  274. return &p
  275. }
  276. // WithButton mouse button (default: "none").
  277. func (p DispatchMouseEventParams) WithButton(button MouseButton) *DispatchMouseEventParams {
  278. p.Button = button
  279. return &p
  280. }
  281. // WithButtons a number indicating which buttons are pressed on the mouse
  282. // when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8,
  283. // Forward=16, None=0.
  284. func (p DispatchMouseEventParams) WithButtons(buttons int64) *DispatchMouseEventParams {
  285. p.Buttons = buttons
  286. return &p
  287. }
  288. // WithClickCount number of times the mouse button was clicked (default: 0).
  289. func (p DispatchMouseEventParams) WithClickCount(clickCount int64) *DispatchMouseEventParams {
  290. p.ClickCount = clickCount
  291. return &p
  292. }
  293. // WithForce the normalized pressure, which has a range of [0,1] (default:
  294. // 0).
  295. func (p DispatchMouseEventParams) WithForce(force float64) *DispatchMouseEventParams {
  296. p.Force = force
  297. return &p
  298. }
  299. // WithTangentialPressure the normalized tangential pressure, which has a
  300. // range of [-1,1] (default: 0).
  301. func (p DispatchMouseEventParams) WithTangentialPressure(tangentialPressure float64) *DispatchMouseEventParams {
  302. p.TangentialPressure = tangentialPressure
  303. return &p
  304. }
  305. // WithTiltX the plane angle between the Y-Z plane and the plane containing
  306. // both the stylus axis and the Y axis, in degrees of the range [-90,90], a
  307. // positive tiltX is to the right (default: 0).
  308. func (p DispatchMouseEventParams) WithTiltX(tiltX float64) *DispatchMouseEventParams {
  309. p.TiltX = tiltX
  310. return &p
  311. }
  312. // WithTiltY the plane angle between the X-Z plane and the plane containing
  313. // both the stylus axis and the X axis, in degrees of the range [-90,90], a
  314. // positive tiltY is towards the user (default: 0).
  315. func (p DispatchMouseEventParams) WithTiltY(tiltY float64) *DispatchMouseEventParams {
  316. p.TiltY = tiltY
  317. return &p
  318. }
  319. // WithTwist the clockwise rotation of a pen stylus around its own major
  320. // axis, in degrees in the range [0,359] (default: 0).
  321. func (p DispatchMouseEventParams) WithTwist(twist int64) *DispatchMouseEventParams {
  322. p.Twist = twist
  323. return &p
  324. }
  325. // WithDeltaX X delta in CSS pixels for mouse wheel event (default: 0).
  326. func (p DispatchMouseEventParams) WithDeltaX(deltaX float64) *DispatchMouseEventParams {
  327. p.DeltaX = deltaX
  328. return &p
  329. }
  330. // WithDeltaY Y delta in CSS pixels for mouse wheel event (default: 0).
  331. func (p DispatchMouseEventParams) WithDeltaY(deltaY float64) *DispatchMouseEventParams {
  332. p.DeltaY = deltaY
  333. return &p
  334. }
  335. // WithPointerType pointer type (default: "mouse").
  336. func (p DispatchMouseEventParams) WithPointerType(pointerType DispatchMouseEventPointerType) *DispatchMouseEventParams {
  337. p.PointerType = pointerType
  338. return &p
  339. }
  340. // Do executes Input.dispatchMouseEvent against the provided context.
  341. func (p *DispatchMouseEventParams) Do(ctx context.Context) (err error) {
  342. return cdp.Execute(ctx, CommandDispatchMouseEvent, p, nil)
  343. }
  344. // DispatchTouchEventParams dispatches a touch event to the page.
  345. type DispatchTouchEventParams struct {
  346. Type TouchType `json:"type"` // Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while TouchStart and TouchMove must contains at least one.
  347. TouchPoints []*TouchPoint `json:"touchPoints"` // Active touch points on the touch device. One event per any changed point (compared to previous touch event in a sequence) is generated, emulating pressing/moving/releasing points one by one.
  348. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  349. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty"` // Time at which the event occurred.
  350. }
  351. // DispatchTouchEvent dispatches a touch event to the page.
  352. //
  353. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchTouchEvent
  354. //
  355. // parameters:
  356. //
  357. // type - Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while TouchStart and TouchMove must contains at least one.
  358. // touchPoints - Active touch points on the touch device. One event per any changed point (compared to previous touch event in a sequence) is generated, emulating pressing/moving/releasing points one by one.
  359. func DispatchTouchEvent(typeVal TouchType, touchPoints []*TouchPoint) *DispatchTouchEventParams {
  360. return &DispatchTouchEventParams{
  361. Type: typeVal,
  362. TouchPoints: touchPoints,
  363. }
  364. }
  365. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  366. // Meta/Command=4, Shift=8 (default: 0).
  367. func (p DispatchTouchEventParams) WithModifiers(modifiers Modifier) *DispatchTouchEventParams {
  368. p.Modifiers = modifiers
  369. return &p
  370. }
  371. // WithTimestamp time at which the event occurred.
  372. func (p DispatchTouchEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *DispatchTouchEventParams {
  373. p.Timestamp = timestamp
  374. return &p
  375. }
  376. // Do executes Input.dispatchTouchEvent against the provided context.
  377. func (p *DispatchTouchEventParams) Do(ctx context.Context) (err error) {
  378. return cdp.Execute(ctx, CommandDispatchTouchEvent, p, nil)
  379. }
  380. // CancelDraggingParams cancels any active dragging in the page.
  381. type CancelDraggingParams struct{}
  382. // CancelDragging cancels any active dragging in the page.
  383. //
  384. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-cancelDragging
  385. func CancelDragging() *CancelDraggingParams {
  386. return &CancelDraggingParams{}
  387. }
  388. // Do executes Input.cancelDragging against the provided context.
  389. func (p *CancelDraggingParams) Do(ctx context.Context) (err error) {
  390. return cdp.Execute(ctx, CommandCancelDragging, nil, nil)
  391. }
  392. // EmulateTouchFromMouseEventParams emulates touch event from the mouse event
  393. // parameters.
  394. type EmulateTouchFromMouseEventParams struct {
  395. Type MouseType `json:"type"` // Type of the mouse event.
  396. X int64 `json:"x"` // X coordinate of the mouse pointer in DIP.
  397. Y int64 `json:"y"` // Y coordinate of the mouse pointer in DIP.
  398. Button MouseButton `json:"button"` // Mouse button. Only "none", "left", "right" are supported.
  399. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty"` // Time at which the event occurred (default: current time).
  400. DeltaX float64 `json:"deltaX"` // X delta in DIP for mouse wheel event (default: 0).
  401. DeltaY float64 `json:"deltaY"` // Y delta in DIP for mouse wheel event (default: 0).
  402. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  403. ClickCount int64 `json:"clickCount,omitempty"` // Number of times the mouse button was clicked (default: 0).
  404. }
  405. // EmulateTouchFromMouseEvent emulates touch event from the mouse event
  406. // parameters.
  407. //
  408. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-emulateTouchFromMouseEvent
  409. //
  410. // parameters:
  411. //
  412. // type - Type of the mouse event.
  413. // x - X coordinate of the mouse pointer in DIP.
  414. // y - Y coordinate of the mouse pointer in DIP.
  415. // button - Mouse button. Only "none", "left", "right" are supported.
  416. func EmulateTouchFromMouseEvent(typeVal MouseType, x int64, y int64, button MouseButton) *EmulateTouchFromMouseEventParams {
  417. return &EmulateTouchFromMouseEventParams{
  418. Type: typeVal,
  419. X: x,
  420. Y: y,
  421. Button: button,
  422. }
  423. }
  424. // WithTimestamp time at which the event occurred (default: current time).
  425. func (p EmulateTouchFromMouseEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *EmulateTouchFromMouseEventParams {
  426. p.Timestamp = timestamp
  427. return &p
  428. }
  429. // WithDeltaX X delta in DIP for mouse wheel event (default: 0).
  430. func (p EmulateTouchFromMouseEventParams) WithDeltaX(deltaX float64) *EmulateTouchFromMouseEventParams {
  431. p.DeltaX = deltaX
  432. return &p
  433. }
  434. // WithDeltaY Y delta in DIP for mouse wheel event (default: 0).
  435. func (p EmulateTouchFromMouseEventParams) WithDeltaY(deltaY float64) *EmulateTouchFromMouseEventParams {
  436. p.DeltaY = deltaY
  437. return &p
  438. }
  439. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  440. // Meta/Command=4, Shift=8 (default: 0).
  441. func (p EmulateTouchFromMouseEventParams) WithModifiers(modifiers Modifier) *EmulateTouchFromMouseEventParams {
  442. p.Modifiers = modifiers
  443. return &p
  444. }
  445. // WithClickCount number of times the mouse button was clicked (default: 0).
  446. func (p EmulateTouchFromMouseEventParams) WithClickCount(clickCount int64) *EmulateTouchFromMouseEventParams {
  447. p.ClickCount = clickCount
  448. return &p
  449. }
  450. // Do executes Input.emulateTouchFromMouseEvent against the provided context.
  451. func (p *EmulateTouchFromMouseEventParams) Do(ctx context.Context) (err error) {
  452. return cdp.Execute(ctx, CommandEmulateTouchFromMouseEvent, p, nil)
  453. }
  454. // SetIgnoreInputEventsParams ignores input events (useful while auditing
  455. // page).
  456. type SetIgnoreInputEventsParams struct {
  457. Ignore bool `json:"ignore"` // Ignores input events processing when set to true.
  458. }
  459. // SetIgnoreInputEvents ignores input events (useful while auditing page).
  460. //
  461. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-setIgnoreInputEvents
  462. //
  463. // parameters:
  464. //
  465. // ignore - Ignores input events processing when set to true.
  466. func SetIgnoreInputEvents(ignore bool) *SetIgnoreInputEventsParams {
  467. return &SetIgnoreInputEventsParams{
  468. Ignore: ignore,
  469. }
  470. }
  471. // Do executes Input.setIgnoreInputEvents against the provided context.
  472. func (p *SetIgnoreInputEventsParams) Do(ctx context.Context) (err error) {
  473. return cdp.Execute(ctx, CommandSetIgnoreInputEvents, p, nil)
  474. }
  475. // SetInterceptDragsParams prevents default drag and drop behavior and
  476. // instead emits Input.dragIntercepted events. Drag and drop behavior can be
  477. // directly controlled via Input.dispatchDragEvent.
  478. type SetInterceptDragsParams struct {
  479. Enabled bool `json:"enabled"`
  480. }
  481. // SetInterceptDrags prevents default drag and drop behavior and instead
  482. // emits Input.dragIntercepted events. Drag and drop behavior can be directly
  483. // controlled via Input.dispatchDragEvent.
  484. //
  485. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-setInterceptDrags
  486. //
  487. // parameters:
  488. //
  489. // enabled
  490. func SetInterceptDrags(enabled bool) *SetInterceptDragsParams {
  491. return &SetInterceptDragsParams{
  492. Enabled: enabled,
  493. }
  494. }
  495. // Do executes Input.setInterceptDrags against the provided context.
  496. func (p *SetInterceptDragsParams) Do(ctx context.Context) (err error) {
  497. return cdp.Execute(ctx, CommandSetInterceptDrags, p, nil)
  498. }
  499. // SynthesizePinchGestureParams synthesizes a pinch gesture over a time
  500. // period by issuing appropriate touch events.
  501. type SynthesizePinchGestureParams struct {
  502. X float64 `json:"x"` // X coordinate of the start of the gesture in CSS pixels.
  503. Y float64 `json:"y"` // Y coordinate of the start of the gesture in CSS pixels.
  504. ScaleFactor float64 `json:"scaleFactor"` // Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
  505. RelativeSpeed int64 `json:"relativeSpeed,omitempty"` // Relative pointer speed in pixels per second (default: 800).
  506. GestureSourceType GestureSourceType `json:"gestureSourceType,omitempty"` // Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
  507. }
  508. // SynthesizePinchGesture synthesizes a pinch gesture over a time period by
  509. // issuing appropriate touch events.
  510. //
  511. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-synthesizePinchGesture
  512. //
  513. // parameters:
  514. //
  515. // x - X coordinate of the start of the gesture in CSS pixels.
  516. // y - Y coordinate of the start of the gesture in CSS pixels.
  517. // scaleFactor - Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
  518. func SynthesizePinchGesture(x float64, y float64, scaleFactor float64) *SynthesizePinchGestureParams {
  519. return &SynthesizePinchGestureParams{
  520. X: x,
  521. Y: y,
  522. ScaleFactor: scaleFactor,
  523. }
  524. }
  525. // WithRelativeSpeed relative pointer speed in pixels per second (default:
  526. // 800).
  527. func (p SynthesizePinchGestureParams) WithRelativeSpeed(relativeSpeed int64) *SynthesizePinchGestureParams {
  528. p.RelativeSpeed = relativeSpeed
  529. return &p
  530. }
  531. // WithGestureSourceType which type of input events to be generated (default:
  532. // 'default', which queries the platform for the preferred input type).
  533. func (p SynthesizePinchGestureParams) WithGestureSourceType(gestureSourceType GestureSourceType) *SynthesizePinchGestureParams {
  534. p.GestureSourceType = gestureSourceType
  535. return &p
  536. }
  537. // Do executes Input.synthesizePinchGesture against the provided context.
  538. func (p *SynthesizePinchGestureParams) Do(ctx context.Context) (err error) {
  539. return cdp.Execute(ctx, CommandSynthesizePinchGesture, p, nil)
  540. }
  541. // SynthesizeScrollGestureParams synthesizes a scroll gesture over a time
  542. // period by issuing appropriate touch events.
  543. type SynthesizeScrollGestureParams struct {
  544. X float64 `json:"x"` // X coordinate of the start of the gesture in CSS pixels.
  545. Y float64 `json:"y"` // Y coordinate of the start of the gesture in CSS pixels.
  546. XDistance float64 `json:"xDistance,omitempty"` // The distance to scroll along the X axis (positive to scroll left).
  547. YDistance float64 `json:"yDistance,omitempty"` // The distance to scroll along the Y axis (positive to scroll up).
  548. XOverscroll float64 `json:"xOverscroll,omitempty"` // The number of additional pixels to scroll back along the X axis, in addition to the given distance.
  549. YOverscroll float64 `json:"yOverscroll,omitempty"` // The number of additional pixels to scroll back along the Y axis, in addition to the given distance.
  550. PreventFling bool `json:"preventFling,omitempty"` // Prevent fling (default: true).
  551. Speed int64 `json:"speed,omitempty"` // Swipe speed in pixels per second (default: 800).
  552. GestureSourceType GestureSourceType `json:"gestureSourceType,omitempty"` // Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
  553. RepeatCount int64 `json:"repeatCount,omitempty"` // The number of times to repeat the gesture (default: 0).
  554. RepeatDelayMs int64 `json:"repeatDelayMs,omitempty"` // The number of milliseconds delay between each repeat. (default: 250).
  555. InteractionMarkerName string `json:"interactionMarkerName,omitempty"` // The name of the interaction markers to generate, if not empty (default: "").
  556. }
  557. // SynthesizeScrollGesture synthesizes a scroll gesture over a time period by
  558. // issuing appropriate touch events.
  559. //
  560. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-synthesizeScrollGesture
  561. //
  562. // parameters:
  563. //
  564. // x - X coordinate of the start of the gesture in CSS pixels.
  565. // y - Y coordinate of the start of the gesture in CSS pixels.
  566. func SynthesizeScrollGesture(x float64, y float64) *SynthesizeScrollGestureParams {
  567. return &SynthesizeScrollGestureParams{
  568. X: x,
  569. Y: y,
  570. }
  571. }
  572. // WithXDistance the distance to scroll along the X axis (positive to scroll
  573. // left).
  574. func (p SynthesizeScrollGestureParams) WithXDistance(xDistance float64) *SynthesizeScrollGestureParams {
  575. p.XDistance = xDistance
  576. return &p
  577. }
  578. // WithYDistance the distance to scroll along the Y axis (positive to scroll
  579. // up).
  580. func (p SynthesizeScrollGestureParams) WithYDistance(yDistance float64) *SynthesizeScrollGestureParams {
  581. p.YDistance = yDistance
  582. return &p
  583. }
  584. // WithXOverscroll the number of additional pixels to scroll back along the X
  585. // axis, in addition to the given distance.
  586. func (p SynthesizeScrollGestureParams) WithXOverscroll(xOverscroll float64) *SynthesizeScrollGestureParams {
  587. p.XOverscroll = xOverscroll
  588. return &p
  589. }
  590. // WithYOverscroll the number of additional pixels to scroll back along the Y
  591. // axis, in addition to the given distance.
  592. func (p SynthesizeScrollGestureParams) WithYOverscroll(yOverscroll float64) *SynthesizeScrollGestureParams {
  593. p.YOverscroll = yOverscroll
  594. return &p
  595. }
  596. // WithPreventFling prevent fling (default: true).
  597. func (p SynthesizeScrollGestureParams) WithPreventFling(preventFling bool) *SynthesizeScrollGestureParams {
  598. p.PreventFling = preventFling
  599. return &p
  600. }
  601. // WithSpeed swipe speed in pixels per second (default: 800).
  602. func (p SynthesizeScrollGestureParams) WithSpeed(speed int64) *SynthesizeScrollGestureParams {
  603. p.Speed = speed
  604. return &p
  605. }
  606. // WithGestureSourceType which type of input events to be generated (default:
  607. // 'default', which queries the platform for the preferred input type).
  608. func (p SynthesizeScrollGestureParams) WithGestureSourceType(gestureSourceType GestureSourceType) *SynthesizeScrollGestureParams {
  609. p.GestureSourceType = gestureSourceType
  610. return &p
  611. }
  612. // WithRepeatCount the number of times to repeat the gesture (default: 0).
  613. func (p SynthesizeScrollGestureParams) WithRepeatCount(repeatCount int64) *SynthesizeScrollGestureParams {
  614. p.RepeatCount = repeatCount
  615. return &p
  616. }
  617. // WithRepeatDelayMs the number of milliseconds delay between each repeat.
  618. // (default: 250).
  619. func (p SynthesizeScrollGestureParams) WithRepeatDelayMs(repeatDelayMs int64) *SynthesizeScrollGestureParams {
  620. p.RepeatDelayMs = repeatDelayMs
  621. return &p
  622. }
  623. // WithInteractionMarkerName the name of the interaction markers to generate,
  624. // if not empty (default: "").
  625. func (p SynthesizeScrollGestureParams) WithInteractionMarkerName(interactionMarkerName string) *SynthesizeScrollGestureParams {
  626. p.InteractionMarkerName = interactionMarkerName
  627. return &p
  628. }
  629. // Do executes Input.synthesizeScrollGesture against the provided context.
  630. func (p *SynthesizeScrollGestureParams) Do(ctx context.Context) (err error) {
  631. return cdp.Execute(ctx, CommandSynthesizeScrollGesture, p, nil)
  632. }
  633. // SynthesizeTapGestureParams synthesizes a tap gesture over a time period by
  634. // issuing appropriate touch events.
  635. type SynthesizeTapGestureParams struct {
  636. X float64 `json:"x"` // X coordinate of the start of the gesture in CSS pixels.
  637. Y float64 `json:"y"` // Y coordinate of the start of the gesture in CSS pixels.
  638. Duration int64 `json:"duration,omitempty"` // Duration between touchdown and touchup events in ms (default: 50).
  639. TapCount int64 `json:"tapCount,omitempty"` // Number of times to perform the tap (e.g. 2 for double tap, default: 1).
  640. GestureSourceType GestureSourceType `json:"gestureSourceType,omitempty"` // Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
  641. }
  642. // SynthesizeTapGesture synthesizes a tap gesture over a time period by
  643. // issuing appropriate touch events.
  644. //
  645. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-synthesizeTapGesture
  646. //
  647. // parameters:
  648. //
  649. // x - X coordinate of the start of the gesture in CSS pixels.
  650. // y - Y coordinate of the start of the gesture in CSS pixels.
  651. func SynthesizeTapGesture(x float64, y float64) *SynthesizeTapGestureParams {
  652. return &SynthesizeTapGestureParams{
  653. X: x,
  654. Y: y,
  655. }
  656. }
  657. // WithDuration duration between touchdown and touchup events in ms (default:
  658. // 50).
  659. func (p SynthesizeTapGestureParams) WithDuration(duration int64) *SynthesizeTapGestureParams {
  660. p.Duration = duration
  661. return &p
  662. }
  663. // WithTapCount number of times to perform the tap (e.g. 2 for double tap,
  664. // default: 1).
  665. func (p SynthesizeTapGestureParams) WithTapCount(tapCount int64) *SynthesizeTapGestureParams {
  666. p.TapCount = tapCount
  667. return &p
  668. }
  669. // WithGestureSourceType which type of input events to be generated (default:
  670. // 'default', which queries the platform for the preferred input type).
  671. func (p SynthesizeTapGestureParams) WithGestureSourceType(gestureSourceType GestureSourceType) *SynthesizeTapGestureParams {
  672. p.GestureSourceType = gestureSourceType
  673. return &p
  674. }
  675. // Do executes Input.synthesizeTapGesture against the provided context.
  676. func (p *SynthesizeTapGestureParams) Do(ctx context.Context) (err error) {
  677. return cdp.Execute(ctx, CommandSynthesizeTapGesture, p, nil)
  678. }
  679. // Command names.
  680. const (
  681. CommandDispatchDragEvent = "Input.dispatchDragEvent"
  682. CommandDispatchKeyEvent = "Input.dispatchKeyEvent"
  683. CommandInsertText = "Input.insertText"
  684. CommandImeSetComposition = "Input.imeSetComposition"
  685. CommandDispatchMouseEvent = "Input.dispatchMouseEvent"
  686. CommandDispatchTouchEvent = "Input.dispatchTouchEvent"
  687. CommandCancelDragging = "Input.cancelDragging"
  688. CommandEmulateTouchFromMouseEvent = "Input.emulateTouchFromMouseEvent"
  689. CommandSetIgnoreInputEvents = "Input.setIgnoreInputEvents"
  690. CommandSetInterceptDrags = "Input.setInterceptDrags"
  691. CommandSynthesizePinchGesture = "Input.synthesizePinchGesture"
  692. CommandSynthesizeScrollGesture = "Input.synthesizeScrollGesture"
  693. CommandSynthesizeTapGesture = "Input.synthesizeTapGesture"
  694. )