Open Google Document for editing via Google Apps Script

35 Views Asked by At

I'm trying to programmatically open a google document inside of a Google Apps Script.

The script executes and runs through the function. "HERE" is logged. If I take the value in EMAIL_TEMPLATE_DOC_URL and paste it into a browser the Google Document opens. "LEAVING" is logged.

No errors are logged.

The function runs but no document is displayed/launched for editing.

What am I missing? Ideally I'd like to open the document in an iFrame, but just opening it for editing would be a large part of the battle.

Thoughts?

Thanks in advance.

function editEmailTemplate() {
  try {
    Logger.log("HERE");

    // Attempt to open the document
    Logger.log(EMAIL_TEMPLATE_DOC_URL);
    var doc = DocumentApp.openByUrl(EMAIL_TEMPLATE_DOC_URL);

    Logger.log("LEAVING");

  } catch (error) {
    // Log the error using Logger.log
    Logger.log('Error in editEmailTemplate: ' + error);

    // Optionally, rethrow the error to propagate it further
    throw error;
  }
}

UPDATE: The following works, (I'm using Vue) but it throws several errors. But from what I can tell, everything works.

Is there a better way to do this??

Code:


<!-- New v-dialog for displaying the URL -->
<v-dialog v-model="dialogtrackURL" max-width="800px">
   <v-card>
     <!-- <v-card-title class="text-h5 text-center">Track URL</v-card-title> -->
      <v-card-text>
      <!-- Use an iframe to display the content of the URL -->
      <iframe src="https://docs.google.com/document/d/1vZavPUyadRMflYI_vND_AzjCqLXDDdmy8kr5bYls38w/edit?usp=sharing" width="100%" height="500px" frameborder="0"></iframe>
      </v-card-text>
         <v-card-actions class="d-flex justify-center">
         <v-btn color="blue-darken-1" rounded="xl" width=100px variant="outlined" @click="closetrackURL">Close</v-btn>
         </v-card-actions>
     </v-card>
</v-dialog>

Error: Refused to frame 'https://contacts.google.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors https://docs.google.com".

0

There are 0 best solutions below