docs: Update documentation to include available modules for custom scripts in monitors

This commit is contained in:
Simon Larsen
2025-05-26 12:51:23 +01:00
parent 511b4c9045
commit d8388666ef
3 changed files with 19 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import { JSONObject, JSONValue } from "../../../Types/JSON";
import axios from "axios";
import http from "http";
import https from "https";
import crypto from "crypto";
import vm, { Context } from "node:vm";
import CaptureSpan from "../Telemetry/CaptureSpan";
@@ -31,6 +32,7 @@ export default class VMRunner {
http: http,
https: https,
axios: axios,
crypto: crypto,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
setInterval: setInterval,

View File

@@ -49,10 +49,17 @@ let booleanSecret = {{monitorSecrets.BooleanSecret}};
console.log(stringSecret);
```
### Modules available in the script
- `axios`: You can use this module to make HTTP requests. It is a promise-based HTTP client for the browser and Node.js.
- `crypto`: You can use this module to perform cryptographic operations. It is a built-in Node.js module that provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
- `console.log`: You can use this module to log data to the console. This is useful for debugging purposes.
- `http`: You can use this module to make HTTP requests. It is a built-in Node.js module that provides an HTTP client and server.
- `https`: You can use this module to make HTTPS requests. It is a built-in Node.js module that provides an HTTPS client and server.
### Things to consider
- You can use `console.log` to log the data in the console. This will be available in the logs section of the monitor (Probes > View Logs).
- You can return the data from the script using the `return` statement.
- This is a JavaScript script, so you can use all the JavaScript features in the script.
- You can use `axios` module to make HTTP requests in the script. You can use it to make API calls from the script.
- Timeout for the script is 2 minutes. If the script takes more than 2 mins, it will be terminated.

View File

@@ -104,6 +104,15 @@ let booleanSecret = {{monitorSecrets.BooleanSecret}};
console.log(stringSecret);
```
### Modules available in the script
- `browser`: You can use this module to interact with the browser. It is a Playwright Browser object that allows you to create new pages, close pages, and perform other browser-related actions.
- `page`: You can use this module to interact with the browser. It is a Playwright Page object that allows you to perform actions like clicking buttons, filling forms, and taking screenshots.
- `axios`: You can use this module to make HTTP requests. It is a promise-based HTTP client for the browser and Node.js.
- `crypto`: You can use this module to perform cryptographic operations. It is a built-in Node.js module that provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
- `console.log`: You can use this module to log data to the console. This is useful for debugging purposes.
- `http`: You can use this module to make HTTP requests. It is a built-in Node.js module that provides an HTTP client and server.
- `https`: You can use this module to make HTTPS requests. It is a built-in Node.js module that provides an HTTPS client and server.
### Things to consider
- You only have `page` object available in the context of the script. This is from Playwright Page class. You can use it to run all the interactions with the browser.