google-apps-scriptgoogle-docs

How to constantly tracking the cursor


I'm currently working with Google Apps Script in Google Docs. I want to track every movement of the cursor, storing the position using the Position.

How can I do?

I created an onOpen function that recalls another function that has an infinite loop inside, trying to store the current position with: DocumentApp.getActiveDocument().getCursor()


Solution

  • TL;DR: Don't do that for serious projects.


    In Google Apps Script,

    1. "Infinite loops" aren't infinite, as there is a time execution limit. Because of this, once the execution reaches the time limit, it will throw an error. Just to let you know, time-driven triggers have a daily total execution time quota. The alternative to this might be to use a sidebar to run the infinite loop using client-side code and google.script.run to call a function that gets the cursor position.

      1. Simple triggers have a 30-second execution time limit.
      2. Installable triggers, as mentioned above, have a daily total time quota.
      3. The official execution time limit is 6 minutes. "Normally", Workspace accounts have 30 minutes limit, but sometimes the official limit is applied.
    2. Google Apps Script services are slow, and there are undisclosed quotas to prevent disruptions in the server operations due to abuse (including edge cases). Because of this, there is a chance that only some of the cursor positions will be correctly logged.


    Related