🧩 Extension

Environment Variables

Extension comes with built-in support for environment variables via .env file (and alikes).

Warning

This feature is not stable yet. You can track its development here.

Take for example, our ChatGPT Template.

ChatGPT Extension Template

See that it expects the EXTENSION_OPENAI_API_KEY environment variable? Create an .env file at the project root so Extension can parse its contents at runtime.

The following file names are supported:

  • .env
  • .env.local
  • .env.defaults
  • .env.example

How To Use

  1. Create a new file using one of the supported file names at the same folder level as your manifest.json file.
  2. In your extension code, add the Node.js pattern of process.env.YOUR_VARIABLE_NAME.

TIP: Environment variables are not supported in the manifest.json file.

See the sample below:

// service_worker.js
const helloWorld = process.env.HELLO_WORLD
console.log(helloWorld)
# .env
HELLO_WORLD=Hello, world!

Will output the following:

// service_worker.js
- const helloWorld = process.env.HELLO_WORLD
+ const helloWorld = "Hello, world!"
console.log(helloWorld)

🧩 Extension • create cross-browser extensions with no build configuration.