Web Standards

The Workers Runtime provides the following standardized APIs for use by scripts running at the Edge.

JavaScript Standards

All of the standard built-in objects supported by the current Google Chrome stable release are supported, with a few notable exceptions:

  • eval() is not allowed for security reasons.
  • new Function is not allowed for security reasons.
  • Date.now() returns the time of the last I/O; it does not advance during code execution.

Web Global APIs

The following methods are available per the Worker Global Scope:

Base64 Utility Methods

atob() - Decodes a string of data which has been encoded using base-64 encoding.

btoa() - Creates a base-64 encoded ASCII string from a string of binary data.

Timers

setInterval() - Schedules a function to execute every time a given number of milliseconds elapses.

clearInterval() - Cancels the repeated execution set using setInterval().

setTimeout() - Schedules a function to execute in a given amount of time.

clearTimeout() - Cancels the delayed execution set using setTimeout().

*Note: Timers are only available inside of the Request Context.

Fetch global

fetch() - Starts the process of fetching a resource from the network. See FetchAPI. *Note: The Fetch API is only available inside of the Request Context.

Encoding API

Both TextEncoder and TextDecoder support UTF-8 encoding/decoding.

Go to the docs

URL API

The URL API supports urls conforming to http and https schemes.

Go to the docs