safeGetCanisterEnv
safeGetCanisterEnv<
T>(options):undefined|CanisterEnv&T
Defined in: packages/agent/src/canister-env/index.ts:155
Experimental
Safe version of getCanisterEnv that returns undefined instead of throwing errors.
Type Parameters
Section titled “Type Parameters”T = Record<string, never>
Parameters
Section titled “Parameters”options
Section titled “options”The options for loading the asset canister environment variables
Returns
Section titled “Returns”undefined | CanisterEnv & T
The environment variables for the asset canister, or undefined if any error occurs
The Canister Environment Guide for more details on how to use the canister environment in a frontend application
Example
Section titled “Example”// in a browser environment with valid cookieconst env = safeGetCanisterEnv();console.log(env); // { IC_ROOT_KEY: Uint8Array, ... }
// in a Node.js environmentconst env = safeGetCanisterEnv();console.log(env); // undefined
// in a browser without the environment cookieconst env = safeGetCanisterEnv();console.log(env); // undefined