Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DispatchMouseEvent does not support mouseWheel along one axis #491

Closed
wtsuench opened this issue Oct 15, 2019 · 2 comments
Closed

DispatchMouseEvent does not support mouseWheel along one axis #491

wtsuench opened this issue Oct 15, 2019 · 2 comments

Comments

@wtsuench
Copy link

wtsuench commented Oct 15, 2019

What versions are you running?

$ go list -m github.com/chromedp/chromedp
$ google-chrome --version
$ go version

github.com/chromedp/chromedp
Version 77.0.3865.90
go version go1.12.7 darwin/amd64

What did you do? Include clear steps.

I'm trying to implement the mouseWheel event,

p := input.DispatchMouseEvent(input.MouseWheel, 0, 0)
p = p.WithDeltaX(0)
p = p.WithDeltaY(float64(y))
err = p.Do(ctx)

without scrolling along the x-axis p.WithDeltaX(0).

What did you expect to see?

MouseWheel event triggered and webpage scrolls to y, without scrolling x.

What did you see instead?

Error 'deltaX' and 'deltaY' are expected for mouseWheel event (-32602)

Confusion?

Can we not scroll y without x?

type DispatchMouseEventParams struct {
	Type        MouseType                     `json:"type"`                  // Type of the mouse event.
	X           float64                       `json:"x"`                     // X coordinate of the event relative to the main frame's viewport in CSS pixels.
	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.
	Modifiers   Modifier                      `json:"modifiers"`             // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
	Timestamp   *TimeSinceEpoch               `json:"timestamp,omitempty"`   // Time at which the event occurred.
	Button      ButtonType                    `json:"button,omitempty"`      // Mouse button (default: "none").
	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.
	ClickCount  int64                         `json:"clickCount,omitempty"`  // Number of times the mouse button was clicked (default: 0).
	DeltaX      float64                       `json:"deltaX,omitempty"`      // X delta in CSS pixels for mouse wheel event (default: 0).
	DeltaY      float64                       `json:"deltaY,omitempty"`      // Y delta in CSS pixels for mouse wheel event (default: 0).
	PointerType DispatchMouseEventPointerType `json:"pointerType,omitempty"` // Pointer type (default: "mouse").
}

During the encoding they are ignored, not sure if this is the part causing the error?

	if in.DeltaX != 0 {
		const prefix string = ",\"deltaX\":"
		out.RawString(prefix)
		out.Float64(float64(in.DeltaX))
	}
	if in.DeltaY != 0 {
		const prefix string = ",\"deltaY\":"
		out.RawString(prefix)
		out.Float64(float64(in.DeltaY))
	}
@wtsuench
Copy link
Author

Can we not make DeltaX and DeltaY a pointer instead?

type DispatchMouseEventParams struct {
	Type        MouseType                     `json:"type"`                  // Type of the mouse event.
	X           float64                       `json:"x"`                     // X coordinate of the event relative to the main frame's viewport in CSS pixels.
	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.
	Modifiers   Modifier                      `json:"modifiers"`             // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
	Timestamp   *TimeSinceEpoch               `json:"timestamp,omitempty"`   // Time at which the event occurred.
	Button      ButtonType                    `json:"button,omitempty"`      // Mouse button (default: "none").
	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.
	ClickCount  int64                         `json:"clickCount,omitempty"`  // Number of times the mouse button was clicked (default: 0).
	DeltaX      *float64                      `json:"deltaX,omitempty"`      // X delta in CSS pixels for mouse wheel event (default: 0).
	DeltaY      *float64                      `json:"deltaY,omitempty"`      // Y delta in CSS pixels for mouse wheel event (default: 0).
	PointerType DispatchMouseEventPointerType `json:"pointerType,omitempty"` // Pointer type (default: "mouse").
}

then update encoding to,

	if in.DeltaX != nil {
		const prefix string = ",\"deltaX\":"
		out.RawString(prefix)
		out.Float64(float64(*in.DeltaX))
	}
	if in.DeltaY != nil {
		const prefix string = ",\"deltaY\":"
		out.RawString(prefix)
		out.Float64(float64(*in.DeltaY))
	}

and update the DispatchMouseEventParams,

// WithDeltaX X delta in CSS pixels for mouse wheel event (default: 0).
func (p DispatchMouseEventParams) WithDeltaX(deltaX float64) *DispatchMouseEventParams {
	p.DeltaX = &deltaX
	return &p
}

// WithDeltaY Y delta in CSS pixels for mouse wheel event (default: 0).
func (p DispatchMouseEventParams) WithDeltaY(deltaY float64) *DispatchMouseEventParams {
	p.DeltaY = &deltaY
	return &p
}

and update decode to,

		case "deltaX":
			f := float64(in.Float64())
			out.DeltaX = &f
		case "deltaY":
			f := float64(in.Float64())
			out.DeltaY = &f

@ZekeLu
Copy link
Member

ZekeLu commented May 18, 2021

@wtsuench Sorry for the late response! And thank you for reporting this issue! I have a fix for it. Let's track the issue over chromedp/pdlgen#10.

@ZekeLu ZekeLu closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants