Available Contexts
Bruno scripts run in a sandboxed JavaScript environment with access to:- Pre-request scripts (
script:pre-request): Run before the request is sent - Post-response scripts (
script:post-response): Run after the response is received - Tests (
tests): Run after the response to validate results
Global Objects
All scripts have access to these global objects:object
The main Bruno API object for managing variables, environment, and request flow
BrunoRequest
The request object (available in pre-request and post-response scripts)
BrunoResponse
The response object (available in post-response scripts and tests only)
function
Function to define test assertions
object
Chai’s expect assertion library
object
Chai’s assert assertion library
object
Console logging object with
log(), info(), warn(), error(), and debug() methodsBuilt-in Libraries
Bruno includes several built-in libraries that you can access usingrequire():
chai
Assertion library (automatically available as
expect and assert)moment
Date and time manipulation library
btoa
Base64 encoding function
atob
Base64 decoding function
crypto-js
Cryptographic functions
jsonwebtoken
JWT creation and verification
buffer
Buffer implementation for binary data
tv4
JSON schema validation
Example Usage
Script Execution Order
When a request is executed, scripts run in this order:- Pre-request script - Modify request before sending
- HTTP Request - Send the request
- Post-response script - Process the response
- Assertions - Run declarative assertions from
assertblock - Tests - Run test scripts
Runtime Modes
Bruno supports two runtime modes:Safe Mode (QuickJS)
Safe Mode (QuickJS)
The default runtime that provides a secure, sandboxed environment. Recommended for most use cases.
- Limited file system access
- Better security
- Faster startup time
Node VM Mode
Node VM Mode
A more permissive runtime with full Node.js capabilities. Enable this in collection settings for advanced scripting needs.
- Full file system access
- Additional Node.js modules
- Custom library imports
Next Steps
Pre-request API
Modify requests before they are sent
Post-response API
Process responses and extract data
Test API
Write assertions and validate responses
Advanced Scripting
Common scripting patterns and examples