log_actions method

Future<Online> log_actions()

log actions logs all user actions like clicks, typing, scrolling, etc in a structured format so that we can use it to write automation scripts

Implementation

Future<Online> log_actions() async {
  await (await page).exposeFunction('log_action', (String action, target) {
    Show.user_action(action, target);
  });

  //create a listener for all user actions and redirect them to the log_action function
  await (await page).evaluateOnNewDocument('''() => {
    document.addEventListener('click', (e) => {
      window.log_action('click', e.target);
    });
    document.addEventListener('contextmenu', (e) => {
      window.log_action('right click', e.target);
    });
    document.addEventListener('dblclick', (e) => {
      window.log_action('double click', e.target);
    });
    document.addEventListener('mouseover', (e) => {
      window.log_action('hover', e.target);
    });
    document.addEventListener('mousedown', (e) => {
      window.log_action('mouse down', e.target);
    });
    document.addEventListener('mouseup', (e) => {
      window.log_action('mouse up', e.target);
    });
    document.addEventListener('keydown', (e) => {
      window.log_action('key down', e.target);
    });
    document.addEventListener('keyup', (e) => {
      window.log_action('key up', e.target);
    });
    document.addEventListener('scroll', (e) => {
      window.log_action('scroll', e.target);
    });
    document.addEventListener('input', (e) => {
      window.log_action('input', e.target);
    });
    document.addEventListener('change', (e) => {
      window.log_action('change', e.target);
    });
  }''');
  return this;
}