Core API
do()
Execute a custom function within the queue.
do()
Execute any custom logic natively within the chain, pausing the execution while it runs and then safely resuming. do() is exceptionally useful for logic requiring programmatic cycles or accessing third-party logic.
Use Cases
- Adding state to the application: Useful for updating a variable or triggering logic in a third-party system.
- Adding an achievement: Granting points or a badge to the user in a gaming or educational context.
- Creating a loop: Setting up an asynchronous loop inside
.do()to trigger cursor object methods (likemove,click, etc.) sequentially.
Loop Example
const cursor = new Cursor();
cursor
.hover('#start-loop')
.do(async (c) => {
// A loop clicking a button 3 times
for (let i = 0; i < 3; i++) {
c.move('#target-btn');
c.click('#target-btn');
c.wait(500); // wait half a second
}
})
.click('#finish');Standard Example
const cursor = new Cursor();
cursor
.hover('#btn-start')
.do(() => {
// Custom logic here
console.log("Custom code executing in the middle of a cursor sequence.");
})
.click('#btn-start');