Skip to content

Commit

Permalink
fix: improve mouse actions (#10021)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Apr 17, 2023
1 parent 285c791 commit 34db39e
Show file tree
Hide file tree
Showing 12 changed files with 400 additions and 109 deletions.
3 changes: 3 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ sidebar_label: API
| [LaunchOptions](./puppeteer.launchoptions.md) | Generic launch options that can be passed when launching any browser. |
| [MediaFeature](./puppeteer.mediafeature.md) | |
| [Metrics](./puppeteer.metrics.md) | |
| [MouseClickOptions](./puppeteer.mouseclickoptions.md) | |
| [MouseMoveOptions](./puppeteer.mousemoveoptions.md) | |
| [MouseOptions](./puppeteer.mouseoptions.md) | |
| [MouseWheelOptions](./puppeteer.mousewheeloptions.md) | |
| [NetworkConditions](./puppeteer.networkconditions.md) | |
Expand Down Expand Up @@ -135,6 +137,7 @@ sidebar_label: API
| [executablePath](./puppeteer.executablepath.md) | |
| [KnownDevices](./puppeteer.knowndevices.md) | A list of devices to be used with [Page.emulate()](./puppeteer.page.emulate.md). |
| [launch](./puppeteer.launch.md) | |
| [MouseButton](./puppeteer.mousebutton.md) | Enum of valid mouse buttons. |
| [networkConditions](./puppeteer.networkconditions.md) | |
| [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md) | A list of network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md). |
| [puppeteer](./puppeteer.puppeteer.md) | |
Expand Down
18 changes: 6 additions & 12 deletions docs/api/puppeteer.mouse.click.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ Shortcut for `mouse.move`, `mouse.down` and `mouse.up`.

```typescript
class Mouse {
click(
x: number,
y: number,
options?: MouseOptions & {
delay?: number;
}
): Promise<void>;
click(x: number, y: number, options?: MouseClickOptions): Promise<void>;
}
```

## Parameters

| Parameter | Type | Description |
| --------- | --------------------------------------------------------------------- | ------------------------------------------------ |
| x | number | Horizontal position of the mouse. |
| y | number | Vertical position of the mouse. |
| options | [MouseOptions](./puppeteer.mouseoptions.md) &amp; { delay?: number; } | _(Optional)_ Optional <code>MouseOptions</code>. |
| Parameter | Type | Description |
| --------- | ----------------------------------------------------- | ------------------------------------------- |
| x | number | Horizontal position of the mouse. |
| y | number | Vertical position of the mouse. |
| options | [MouseClickOptions](./puppeteer.mouseclickoptions.md) | _(Optional)_ Options to configure behavior. |

**Returns:**

Expand Down
8 changes: 4 additions & 4 deletions docs/api/puppeteer.mouse.down.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_label: Mouse.down

# Mouse.down() method

Dispatches a `mousedown` event.
Presses the mouse.

#### Signature:

Expand All @@ -16,9 +16,9 @@ class Mouse {

## Parameters

| Parameter | Type | Description |
| --------- | ------------------------------------------- | ------------------------------------------------ |
| options | [MouseOptions](./puppeteer.mouseoptions.md) | _(Optional)_ Optional <code>MouseOptions</code>. |
| Parameter | Type | Description |
| --------- | ------------------------------------------- | ------------------------------------------- |
| options | [MouseOptions](./puppeteer.mouseoptions.md) | _(Optional)_ Options to configure behavior. |

**Returns:**

Expand Down
6 changes: 3 additions & 3 deletions docs/api/puppeteer.mouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ await browser
| Method | Modifiers | Description |
| ----------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------- |
| [click(x, y, options)](./puppeteer.mouse.click.md) | | Shortcut for <code>mouse.move</code>, <code>mouse.down</code> and <code>mouse.up</code>. |
| [down(options)](./puppeteer.mouse.down.md) | | Dispatches a <code>mousedown</code> event. |
| [down(options)](./puppeteer.mouse.down.md) | | Presses the mouse. |
| [drag(start, target)](./puppeteer.mouse.drag.md) | | Dispatches a <code>drag</code> event. |
| [dragAndDrop(start, target, options)](./puppeteer.mouse.draganddrop.md) | | Performs a drag, dragenter, dragover, and drop in sequence. |
| [dragEnter(target, data)](./puppeteer.mouse.dragenter.md) | | Dispatches a <code>dragenter</code> event. |
| [dragOver(target, data)](./puppeteer.mouse.dragover.md) | | Dispatches a <code>dragover</code> event. |
| [drop(target, data)](./puppeteer.mouse.drop.md) | | Performs a dragenter, dragover, and drop in sequence. |
| [move(x, y, options)](./puppeteer.mouse.move.md) | | Dispatches a <code>mousemove</code> event. |
| [up(options)](./puppeteer.mouse.up.md) | | Dispatches a <code>mouseup</code> event. |
| [move(x, y, options)](./puppeteer.mouse.move.md) | | Moves the mouse to the given coordinate. |
| [up(options)](./puppeteer.mouse.up.md) | | Releases the mouse. |
| [wheel(options)](./puppeteer.mouse.wheel.md) | | Dispatches a <code>mousewheel</code> event. |
20 changes: 7 additions & 13 deletions docs/api/puppeteer.mouse.move.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@ sidebar_label: Mouse.move

# Mouse.move() method

Dispatches a `mousemove` event.
Moves the mouse to the given coordinate.

#### Signature:

```typescript
class Mouse {
move(
x: number,
y: number,
options?: {
steps?: number;
}
): Promise<void>;
move(x: number, y: number, options?: MouseMoveOptions): Promise<void>;
}
```

## Parameters

| Parameter | Type | Description |
| --------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| x | number | Horizontal position of the mouse. |
| y | number | Vertical position of the mouse. |
| options | { steps?: number; } | _(Optional)_ Optional object. If specified, the <code>steps</code> property sends intermediate <code>mousemove</code> events when set to <code>1</code> (default). |
| Parameter | Type | Description |
| --------- | --------------------------------------------------- | ------------------------------------------- |
| x | number | Horizontal position of the mouse. |
| y | number | Vertical position of the mouse. |
| options | [MouseMoveOptions](./puppeteer.mousemoveoptions.md) | _(Optional)_ Options to configure behavior. |

**Returns:**

Expand Down
8 changes: 4 additions & 4 deletions docs/api/puppeteer.mouse.up.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_label: Mouse.up

# Mouse.up() method

Dispatches a `mouseup` event.
Releases the mouse.

#### Signature:

Expand All @@ -16,9 +16,9 @@ class Mouse {

## Parameters

| Parameter | Type | Description |
| --------- | ------------------------------------------- | ------------------------------------------------ |
| options | [MouseOptions](./puppeteer.mouseoptions.md) | _(Optional)_ Optional <code>MouseOptions</code>. |
| Parameter | Type | Description |
| --------- | ------------------------------------------- | ------------------------------------------- |
| options | [MouseOptions](./puppeteer.mouseoptions.md) | _(Optional)_ Options to configure behavior. |

**Returns:**

Expand Down
12 changes: 10 additions & 2 deletions docs/api/puppeteer.mousebutton.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
sidebar_label: MouseButton
---

# MouseButton type
# MouseButton variable

Enum of valid mouse buttons.

#### Signature:

```typescript
export type MouseButton = 'left' | 'right' | 'middle' | 'back' | 'forward';
MouseButton: Readonly<{
Left: 'left';
Right: 'right';
Middle: 'middle';
Back: 'back';
Forward: 'forward';
}>;
```
19 changes: 19 additions & 0 deletions docs/api/puppeteer.mouseclickoptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
sidebar_label: MouseClickOptions
---

# MouseClickOptions interface

#### Signature:

```typescript
export interface MouseClickOptions extends MouseOptions
```
**Extends:** [MouseOptions](./puppeteer.mouseoptions.md)
## Properties
| Property | Modifiers | Type | Description | Default |
| -------- | --------------------- | ------ | -------------------------------------------------------------- | ------- |
| delay | <code>optional</code> | number | Time (in ms) to delay the mouse release after the mouse press. | |
17 changes: 17 additions & 0 deletions docs/api/puppeteer.mousemoveoptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
sidebar_label: MouseMoveOptions
---

# MouseMoveOptions interface

#### Signature:

```typescript
export interface MouseMoveOptions
```

## Properties

| Property | Modifiers | Type | Description | Default |
| -------- | --------------------- | ------ | ------------------------------------------------------------------------------------------ | -------------- |
| steps | <code>optional</code> | number | Determines the number of movements to make from the current mouse position to the new one. | <code>1</code> |
8 changes: 4 additions & 4 deletions docs/api/puppeteer.mouseoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface MouseOptions

## Properties

| Property | Modifiers | Type | Description | Default |
| ---------- | --------------------- | ----------------------------------------- | ----------- | ------- |
| button | <code>optional</code> | [MouseButton](./puppeteer.mousebutton.md) | | |
| clickCount | <code>optional</code> | number | | |
| Property | Modifiers | Type | Description | Default |
| ---------- | --------------------- | ----------------------------------------- | ----------------------------------------- | ------------------- |
| button | <code>optional</code> | [MouseButton](./puppeteer.mousebutton.md) | Determines which button will be pressed. | <code>'left'</code> |
| clickCount | <code>optional</code> | number | Determines the click count for the mouse. | <code>1</code> |
Loading

0 comments on commit 34db39e

Please sign in to comment.