Actually, it IS possible for Client scripts to run in a non-UI context. I only know this because for years we used a bundle in which a client script performed key actions on Sales Orders, and we reported that we were getting errors creating sales orders via script or CSV import. NetSuite (the creator of the bundle) made a change so that the client script could be triggered by those methods as well, and it ran that way for years.
If you go to the script deployment for the client script, there is a Context Filtering tab, and an Execution Context multi-select field. You can try unselecting some of the execution contexts to see if that can avoid the error.
It’s very strange to think of a client script running in a non-UI context, but it can happen, and there may be some reasons for doing so.