Apps Script V8 Runtime Limitations

Published on Markdown

Google Apps Script is a cloud-based scripting platform that lets you automate tasks, customize functions, and build solutions within Google Workspace using JavaScript and the V8 runtime. V8 is the JavaScript engine that powers Google Chrome and Node.js. However, the runtime has some limitations that you should be aware of when developing Apps Script projects and not all JavaScript functions and interfaces are supported.

WinterCG Minimum Common Web Platform API

This is similar to the challenges being addressed by the Web-interoperable Runtimes Community Group (WinterCG) project, which aims to improve API interoperability across different JavaScript runtimes. The WinterCG has a draft Minimum Common Web Platform API proposal that aims to define a minimum set of APIs that should be available in all JavaScript runtimes. I took this draft and tested the APIs in the Apps Script V8 runtime to see which ones are supported and which ones are not. Below are the results generated by the script:

JavaScript APIs and availability in Apps Script V8

JavaScript APIAvailableError
AbortControllerAbortController is not defined
AbortSignalAbortSignal is not defined
atobatob is not defined
BlobBlob is not defined
btoabtoa is not defined
ByteLengthQueuingStrategyByteLengthQueuingStrategy is not defined
clearIntervalclearInterval is not defined
clearTimeoutclearTimeout is not defined
CompressionStreamCompressionStream is not defined
console-
CountQueuingStrategyCountQueuingStrategy is not defined
cryptocrypto is not defined
CryptoCrypto is not defined
CryptoKeyCryptoKey is not defined
DecompressionStreamDecompressionStream is not defined
DOMExceptionDOMException is not defined
EventEvent is not defined
EventTargetEventTarget is not defined
fetchfetch is not defined
FileFile is not defined
FormDataFormData is not defined
HeadersHeaders is not defined
navigator.userAgentnavigator is not defined
performance.nowperformance is not defined
performance.timeOriginperformance is not defined
queueMicrotaskqueueMicrotask is not defined
ReadableByteStreamControllerReadableByteStreamController is not defined
ReadableStreamReadableStream is not defined
ReadableStreamBYOBReaderReadableStreamBYOBReader is not defined
ReadableStreamBYOBRequestReadableStreamBYOBRequest is not defined
ReadableStreamDefaultControllerReadableStreamDefaultController is not defined
ReadableStreamDefaultReaderReadableStreamDefaultReader is not defined
RequestRequest is not defined
ResponseResponse is not defined
setIntervalsetInterval is not defined
setTimeoutsetTimeout is not defined
structuredClonestructuredClone is not defined
SubtleCryptoSubtleCrypto is not defined
TextDecoderTextDecoder is not defined
TextDecoderStreamTextDecoderStream is not defined
TextEncoderTextEncoder is not defined
TextEncoderStreamTextEncoderStream is not defined
TransformStreamTransformStream is not defined
TransformStreamDefaultControllerTransformStreamDefaultController is not defined
URLURL is not defined
URLSearchParamsURLSearchParams is not defined
WebAssembly.compile-
WebAssembly.compileStreamingWebAssembly.compileStreaming is not a function
WebAssembly.Global-
WebAssembly.Instance-
WebAssembly.instantiate-
WebAssembly.instantiateStreamingWebAssembly.instantiateStreaming is not a function
WebAssembly.Memory-
WebAssembly.Module-
WebAssembly.Table-
WebAssembly.validate-
WritableStreamWritableStream is not defined
WritableStreamDefaultControllerWritableStreamDefaultController is not defined

Runtime workarounds

For some APIs there is an Apps Script specific alternative. For example, the fetch API is not available in Apps Script, but you can use the UrlFetchApp service instead.

// fetch('https://api.example.com/data')
UrlFetchApp.fetch("https://api.example.com/data");

Other examples such as setTimeout and setInterval are not available in Apps Script, but you can use the Utilities.sleep method.

// setTimeout(() => console.log('Hello'), 1000)
Utilities.sleep(1000);
console.log("Hello");

It is also possible to use polyfills or workarounds to achieve the same functionality. An example of this is the TextEncoder and TextDecoder interfaces, which are not available in Apps Script, but you can use the util NPM package to achieve the same functionality with some manual setup or bundling outside of Apps Script.

One thing to keep in mind is that streaming functionality is not available in Apps Script and there really isn’t a good workaround for this. However, there is asynchronous support which is needed for the WebAssembly interface!

© 2024 by Justin Poehnelt is licensed under CC BY-SA 4.0