User-like behavior

Overview

This guide shares some technniques to make AgentQL scripts appear more human-like and avoid bot detection strategies.

Randomization

Humans have reliably imperfect interactions with user interfaces—they never move their cursors never in straight lines, they click in random places on elements, and they scroll in unpredictable increments down the page.

Humans are so good at being less than precise that many anti-bot systems measure mouse movements, click coordinates, and scroll lengths to determine how "bot-like" a session is. The solution is to add some randomization to these interactions.

Randomize mouse movements

Unlike scripted movements and interactions, humans don't move their cursor in a straight line. This is one way reCAPTCHA tells human from bot. Adding some random jitter to your interactions helps them appear more human-like.

The following code moves the mouse to a random position on the page at a random interval:

As with random movements, humans also don't click in the same place on an element's bounding box. You can randomize your clicks with the following code, which clicks at a random coordinate within an element's bounding box:

Lastly, humans scroll inconsistently. The following code randomizes the amount the page scrolls down:

Keypresses

Another things humans do but automation software like Playwright doesn't: pressing individual keys, which fires events in the browser that antibot software can listen to. Fortunately, Playwright has a solution for this in <a href="https://playwright.dev/python/docs/api/class-locator#locator-press-sequentially" target="_blank">press_sequentially</a>. This method focuses the element and then sends a keydown, keypress/input, and keyup event for each character in the text. Here's how it looks:

Example

With these randomized actions, your script would look more human-like. For example, you want to scroll down to the bottom of the AgentQL quick start page and click in the "AgentQL query syntax" text button. You can combine the methods you learned to make your script look more human-like.

Conclusion

In this guide, you learned how to make your playwright script look more human-like by randomizing your mouse movements, clicks, and scrolling.