Execute HtmlOutput code in Google App Script without opening a sidebar

。_饼干妹妹 提交于 2020-08-09 09:01:12

问题


edit: wound up using cheerio to manipulate the elements instead of creating them in a sidebar.

Is it possible to create an execute htmlOutput in a background page, or do so without showing the user anything?

Sample code below:

plugin.gs

function onOpen(e) {
    DocumentApp.getUi().createAddonMenu()
        .addItem('Start', 'run')
        .addToUi();
}

/**
 * Opens a sidebar in the document containing the add-on's user interface.
 */
function run() {
    var ui = HtmlService.createTemplateFromFile('sidebar').evaluate()
        .setTitle(constants.title);

    DocumentApp.getUi().showSidebar(ui);
}

sidebar.html

<html>
<head>
<script>
  console.log("Hello world!");
</script>
</head>
</html>

This works, but it pops open the sidebar. If I comment out DocumentApp.getUi().showSidebar(ui);, then the page is never created or executed.

Context: I'd like to run some scripts that need to use basic APIs/DOM manipulation like window, document, etc. These don't run on serverside gs files. I want this to happen without having to open a sidebar.

来源:https://stackoverflow.com/questions/61579707/execute-htmloutput-code-in-google-app-script-without-opening-a-sidebar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!