Development
Find best practices for using the EdgeWorkers service to enhance your website functionality.
As a developer, your goal is to solve problems and improve your website. In the design phase, there are several things to take into consideration. This section includes details about the functions, events, and objects required to write EdgeWorkers code to manipulate HTTP requests and responses.
Specifications
The EdgeWorkers service is built on V8 and supports various ECMAScript language features implemented by the V8 JavaScript engine. APIs commonly used by web developers, that are not part of the language specification itself, are not provided by EdgeWorkers.
The following are examples of common APIs not provided by EdgeWorkers: DOM APIs, Network request APIs such as XMLHttpRequest, and the Fetch API.
JavaScript Language Feature Modifications
Review the table below for information about updates to the JavaScript runtime security.
Feature | Modification | Description |
---|---|---|
SharedArrayBuffer | removed | Sets the V8 Flag --no-harmony-SharedArrayBuffer. Prevents features such as SharedArrayBuffer and Atomics from being used in the API. |
Code Generation | removed | Disables code generation from strings. Prevents features such as new Function () and eval from being used in the API. |
System Time | modified | Prevents time from incrementing during an event handler in the JavaScript API. Features such as Date.now() return the start time of the callback execution. |
WebAssembly | removed | Sets the V8 Flag --no-expose-wasm. Prevents features such as WebAssembly from being used in the API. |
Considerations
The EdgeWorker service compiles scripts as an ECMAScript 6 module. When using an ECMAScript 6 module you must enable strict mode and export the Event handler functions.
Different event handlers may be executed in different instances of the JavaScript Engine. As a result, writes to global JavaScript variables within event handlers are not reliably preserved across separate event handler executions.