Failing in setting textarea value from sidebar.html file

I am developing Google Docs addon, in which I am periodically checking for selected text and updating a textarea in sidebar.html file. Everything works fine as long as the user domain/email is @gmail.com.

If a user comes from a Google Workspace email address (not ending with @gmail.com), the same piece of code is failing with error:

Blocked autofocusing on a <div> element in a cross-origin subframe.

Here is the code to get selected text in Google doc and update the textarea in sidebar.html file.

setInterval(function() {
    google.script.run.withSuccessHandler(function(selectedText) {
        $('#selected-text').focus().val(selectedText[0]);
      }).withFailureHandler(showError).getSelectedText();
  }, 1000);

The getSelectedText() function can be seen here.

I believe this is a cross-origin issue. Please suggest any fix.