Web Apps

If you build a user interface for a script, you can publish the script as aweb app. For example, a script that lets users schedule appointments withmembers of a support team would best be presented as a web app so thatusers can access it directly from their browsers.

Bothstandalone scripts andscripts bound to Google Workspace applicationscan be turned intoweb apps, so long as they meet the requirements below.

Requirements for web apps

A script can be published as a web app if it meets these requirements:

Request parameters

When a user visits an app or a program sends the app an HTTPGET request,Apps Script runs the functiondoGet(e). When a program sends the app an HTTPPOST request, Apps Script runsdoPost(e) instead. In both cases, theeargument represents an event parameter that can contain information about anyrequest parameters. The structure of the event object is shown in the tablebelow:

Fields
e.queryString

The value of the query string portion of the URL, ornull if no query string is specified

name=alice&n=1&n=2
e.parameter

An object of key/value pairs that correspond to the request parameters. Only the first value is returned for parameters that have multiple values.

{"name": "alice", "n": "1"}
e.parameters

An object similar toe.parameter, but with an array of values for each key

{"name": ["alice"], "n": ["1", "2"]}
e.pathInfo

The URL path after/exec or/dev. For example, if the URL path ends in/exec/hello, the path info ishello.

e.contextPathNot used, always the empty string.
e.contentLength

The length of the request body for POST requests, or-1 for GET requests

332
e.postData.length

The same ase.contentLength

332
e.postData.type

The MIME type of the POST body

text/csv
e.postData.contents

The content text of the POST body

Alice,21
e.postData.name

Always the value "postData"

postData

For instance, you could pass parameters such asusername andageto a URL as shown below:

https://script.google.com/.../exec?username=jsmith&age=21

Then, you can display the parameters like so:

functiondoGet(e){varparams=JSON.stringify(e);returnContentService.createTextOutput(params).setMimeType(ContentService.MimeType.JSON);}

In the above example,doGet(e) returns the following output:

{  "queryString": "username=jsmith&age=21",  "parameter": {    "username": "jsmith",    "age": "21"  },  "contextPath": "",  "parameters": {    "username": [      "jsmith"    ],    "age": [      "21"    ]  },  "contentLength": -1}
Warning: The following parameter names are reserved by the system and shouldn'tbe used in URL parameters or POST bodies:
  • c
  • sid
Using these parameters may result in an HTTP 405 response with the error message"Sorry, the file you have requested does not exist." If possible, update yourscript to use different parameter names.

Deploy a script as a web app

To deploy a script as a web app, follow these steps:

  1. At the top right of the script project, clickDeploy >New deployment.
  2. Next to "Select type," click Enable deployment types >Web app.
  3. Enter the information about your web app in the fields under "Deployment configuration."
  4. ClickDeploy.

You can share the web app URL with those you would like to use your app,provided you have granted them access.

Note: Web apps deployed in one domain cease to function if their ownershipchanges to ashared driveor account in a different domain. This can be corrected by having thenew owner or collaborator redeploy the web app in the new domain. Alternatively,if the web app is moved back to its original domain the web app will startfunctioning again for that domain without redeploying.

Test a web app deployment

To test your script as a web app, follow the steps below:

  1. At the top right of the script project, clickDeploy > Test deployments.
  2. Next to "Select type," click Enable deployment types> Web app.
  3. Under the web app URL, clickCopy.
  4. Paste the URL in your browser and test your web app.

    This URL ends in/dev and can only be accessed by users who have edit accessto the script. This instance of the app always runs the most recently savedcode and is only intended for testing during development.

Warning: When deploying web apps to run as the developer, you shouldexercise great care when handling OAuth tokens obtained throughScriptApp.getOAuthToken().These tokens can grant other applications access to your data — nevertransmit them to the client.

Permissions

The permissions for a web app differ depending how you choose to executethe app:

  • Execute the app as me—In this case, the script always executesas you, the owner of the script, no matter who accesses the web app.
  • Execute the app as user accessing the web app—In this case, the scriptruns under the identity of the active user using the web app. This permissionapproach causes the web app to show the email of the script owner when the userauthorizes access.
Warning: To prevent abuse, Apps Script imposes limits on the rateat which new users can authorize a web app that executes as the user. Theselimits depend, among other factors, on whether the publishing account is part ofaGoogle Workspace domain.Note: You can collaborate on web apps usingshared drive.When a web app in a shared drive is deployed, choosing to "execute as you"causes the web app to execute under the authority of the user that deployed it(since there is no script owner).

Embed your web app in Google Sites

Warning: Embedded web apps are still subject to access permissions to preventmalicious use. If your embedded web app doesn't seem to be working, check to seeif the permissions set by the web app owner and the domain administrator allowits use.

In order to embed a web app in Google Sites, it must first bedeployed. You alsoneed theDeployed URL from theDeploy dialog.

To embed a web app into aSitespage, follow these steps:

  1. Open the Sites page where you'd like to add the web app.
  2. SelectInsert > Embed URL.
  3. Paste in the web app URL and then clickADD.

The web app appears in a frame in the page's preview. When you publishthe page, your site viewers may need to authorize the web app before itexecutes normally. Unauthorized web apps present authorization prompts tothe user.

Web Apps and Browser History

It can be desirable to have an Apps Script web app simulate a multi-pageapplication, or one with a dynamic UI controlled via URL parameters.In order to do this well, you can define a state object to represent the app'sUI or page, and push the state into the browser history as theuser navigates your app. You can also listen to history events so that your webapp displays the correct UI when the user navigates back and forth with thebrowser buttons. By querying the URL parameters at load time, you can have yourapp dynamically build its UI based on those parameters, allowing the user tostart the app in a particular state.

Apps Script provides two asynchronous client-side JavaScript APIs to assistwith creating web apps that are linked to the browser history:

  • google.script.historyprovides methods to allow dynamic response to browser history changes. Thisincludes: pushing states (simple Objects you can define) onto the browserhistory, replacing the top state in the history stack, and setting a listenercallback function to respond to history changes.

  • google.script.url providesthe means to retrieve the current page's URL parameters and URL fragment, ifthey are present.

These history APIs are only available to web apps. They are notsupported for sidebars, dialogs or add-ons. This functionality is alsonot recommended for use inweb apps embedded in a Google Sites.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-06-04 UTC.