riflosnake / HumanCursor

Simulate Human Cursor Movement for Automated Scripts
MIT License
84 stars 15 forks source link

Decouple curve creation from driver viewport logic #10

Open cornfeedhobo opened 8 months ago

cornfeedhobo commented 8 months ago

I would like to use this project for it's human curve logic only, and plumb that into my own use case, however the current API is structured to always take in a Driver. I could submit a PR if you're open to this.

riflosnake commented 8 months ago

I assume by human curve logic, you meant HumanizeMouseTrajectory() class, which only takes from_point and to_point integer parameters, and returns a list of x and y coordinates, which can be plotted to show the trajectory.

Also, only WebCursor takes in the driver argument. SystemCursor does not.

But however, i'm open to any pull requests that can add value to the project.

Keep in mind that this is very unreadable, poorly structured code and not actively maintained anymore.

Good luck and thank you!

cornfeedhobo commented 8 months ago

I could be mistaken, but it looks like system_cursor.py and web_adjuster.py both consume generate_random_curve_parameters. The caller can pass their own human_curve, and that is where I arrived at this issue - wanting to use a generalized version of generate_random_curve_parameters. However, after looking more, I'm not sure how to best do this at the moment.

Can you explain what's the intent behind restricting the points when generating for the web?

riflosnake commented 8 months ago

Can you explain what's the intent behind restricting the points when generating for the web?

The tweaking and modifications (including this restricting you mentioned) for the WebCursor, are just my adaptions to make it work, because the ActionChains module of Selenium that I use for actually moving the cursor isn't customizable at all.

I forgot the actual reason, but I couldn't control the duration/speed of the movement at all on the web, and the only solution I found was that : the less points there are => the faster the movement will be, the more points there are => the slower the movement will be.

The correct path was to use a lower-level function that I could build on myself, rather than using ActionChains, but I was a novice back then so...

As for using a generalized version of generate_random_curve_parameters, I don't quite understand your objective, maybe you can further explain?

cornfeedhobo commented 7 months ago

I want to use the curve points generated, for controlling mouse movements while scraping with scrapy-playwright.

riflosnake commented 7 months ago

I want to use the curve points generated, for controlling mouse movements while scraping with scrapy-playwright.

If you can do this: await page.mouse.move(x, y, {'steps': steps, 'delay': duration}) One function of WebAdjuster class is to just convert the absolute coordinate points we get from HumanizeMouseTrajectory().points, to relative offsets from each point, because ActionChains module I used only supported move_by_offset and not a move_to a point, which I think playwright supports.