Skip to content

Trigger synthetic click events

Andrea Cardaci edited this page Dec 4, 2016 · 2 revisions

Trigger a synthetic click event on the given client coordinate (42, 42) then exit.

const CDP = require('chrome-remote-interface');

CDP((client) => {
    const options = {
        x: 42,
        y: 42,
        button: 'left',
        clickCount: 1
    };
    Promise.resolve().then(() => {
        options.type = 'mousePressed';
        return client.Input.dispatchMouseEvent(options);
    }).then(() => {
        options.type = 'mouseReleased';
        return client.Input.dispatchMouseEvent(options);
    }).catch((err) => {
        console.error(err);
    }).then(() => {
        client.close();
    });
}).on('error', (err) => {
    console.error(err);
});