Comments (14)
Here's the example, it works on headless mode:
func main() {
browser := rod.New().Connect()
defer browser.Close()
pageURL := "your url"
page.Navigate(pageURL)
wait := page.WaitRequestIdle()
wait()
box := page.Element(".slider").Box()
kit.Dump(box)
mouse := page.Mouse
mouse.Move(box.Left, box.Top)
mouse.Down("left")
mouse.MoveE(box.Left+100, box.Top, 5) // drag 100px to the right
page.Screenshot("")
mouse.Up("left")
page.Screenshot("")
}
from rod.
I thought Swipe
= Down
- Moves
- Up
, but looked into rod a little, really couldn't move, Down
- Moves
- Up
was more like Click
...
But Move
worked fine when used alone...I mean, without holding the InputMouseButtonLeft
from rod.
Chrome: 83
from rod.
Sorry, this is a known issue:
https://github.com/ysmood/rod/blob/efd99d27e081c6a62603153074a46c3f01759233/page_test.go#L293-L304
from rod.
I still don't know why it doesn't work. Feels like a bug of Chrome
from rod.
If you look at the puppeteer.js, they have the same issue:
from rod.
I still don't know why it doesn't work. Feels like a bug of Chrome
Shocked at this fact...
from rod.
But if you use headless mode, it should work as expected. This issue is only for head mode which means you can't watch it on live. This test shows the events will happen correctly:
https://github.com/ysmood/rod/blob/f59cc63696ec5beef2bc5ec0541bebd3f50330f1/page_test.go#L293-L315
I think the reason is that in head mode chrome will use the position of your real mouse, not the mocked one. A typical race condition bug which is really hard to resolve (since you still want to interact with the controlled page with the real mouse to debug), that's why this bug is there for so many years.
from rod.
You can use the monitor helper to watch what's happening when it runs in the background:
https://github.com/ysmood/rod/blob/f59cc63696ec5beef2bc5ec0541bebd3f50330f1/examples_test.go#L69-L70
from rod.
But if you use headless mode, it should work as expected. This issue is only for head mode which means you can't watch it on live. This test shows the events will happen correctly:
https://github.com/ysmood/rod/blob/f59cc63696ec5beef2bc5ec0541bebd3f50330f1/page_test.go#L293-L315
I think the reason is that in head mode chrome will use the position of your real mouse, not the mocked one. A typical race condition bug which is really hard to resolve (since you still want to interact with the controlled page with the real mouse to debug), that's why this bug is there for so many years.
Thanks @ysmood , but it was still stucked. 😥
from rod.
Ok, I get it now, thanks @ysmood !
from rod.
The latest chrome has fixed this issue, now it works for both headless and headful.
from rod.
page.Element("#pager").Box()
,出现错误,没有这个方法Box()。
from rod.
The code is outdated, check the new doc:
Lines 184 to 197 in b7f9c86
from rod.
Related Issues (20)
- How to open a new Chrome window while using remote control HOT 4
- Using go-rod with firefox, failing to start new instance of firefox HOT 6
- How to disable the dialog when open External protocols HOT 2
- How to Set or replace response headers HOT 2
- Proxy and Hijack HOT 3
- Just a recipe to run a go-rod program as systemd service HOT 1
- How to Log CDP Logs to a File or Use slog HOT 2
- Failed to deserialize params.body - BINDINGS: binary value expected at position 61 HOT 5
- failed page screenshot in defer HOT 2
- launcher docker 是否支持常驻且直接连接 HOT 4
- Examples fail on Ubuntu 24.04 with "No usable sandbox!" HOT 8
- Open the webpage, the page size is changed HOT 1
- Limit the number of redirects and store all accessed URLs HOT 1
- NewUserMode 无法关闭浏览器 HOT 1
- NewUserMode 和 NewManaged 可以同时使用吗 HOT 1
- How do I get Ifram without using--disable-site-isolation-trials? HOT 4
- navigation failed: net::ERR_TUNNEL_CONNECTION_FAILED HOT 1
- using "MustPage" to open the page will simulate a device by default HOT 2
- Any idea about cdp hang at syscall? HOT 1
- Panic on .HTML() HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rod.