New Relic allows you use NerdGraph to create scripted browser monitors. Scripted browser monitors execute custom JavaScript code in a real browser environment, allowing you to simulate complex user interactions and multi-step workflows. This tutorial provides examples of how to use the NerdGraph API to automate the creation of scripted browser monitors.
Create a scripted browser monitor
You can create a scripted browser monitor using the syntheticsCreateScriptBrowserMonitor mutation. This mutation allows you to set up custom scripted monitoring that executes your JavaScript code in a browser.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| Integer | Yes | Your New Relic account ID where the monitor will be created. |
| Array | Yes | Browser(s) that the monitor will use to execute jobs. Supported browsers: |
| Array | Yes | Devices that the monitor will use to execute jobs. Supported devices: |
| Array | Yes | Array of public location identifiers where the monitor will run checks (e.g., |
| String | Yes | The display name for your scripted browser monitor. |
| Enum | Yes | How often the monitor runs. Options: |
| String | Yes | The runtime type used by your monitor. |
| String | Yes | The runtime type version used by your monitor. |
| String | Yes | The language used in your monitor. |
| String | Yes | The JavaScript code that the monitor executes. This should be plain text, not base64 encoded. The script can use Selenium WebDriver APIs to control the browser. |
| Enum | Yes | The monitor status. Options: |
| Boolean | No | Captures a screenshot during job execution when a failure occurs or a script is executed. |
| Float | No | The monitor's Apdex target in seconds, used to populate SLA reports. Defaults to 7.0 seconds. |
Sample request
mutation { syntheticsCreateScriptBrowserMonitor( accountId: ACCOUNT_ID monitor: { browsers: [BROWSERS] devices: [DEVICES] locations: { public: ["LOCATION_1", "LOCATION_2"] } name: "MONITOR_NAME" period: PERIOD runtime: { runtimeType: "RUNTIME_TYPE" runtimeTypeVersion: "RUNTIME_TYPE_VERSION" scriptLanguage: "SCRIPT_LANGUAGE" } script: "SCRIPT_CONTENT" status: STATUS advancedOptions: { enableScreenshotOnFailureAndScript: ENABLE_SCREENSHOT } apdexTarget: APDEX_TARGET } ) { errors { description type } }}Sample response
A successful response returns null for errors:
{ "data": { "syntheticsCreateScriptBrowserMonitor": { "errors": null } }}If there are any issues creating the monitor, the errors array will contain objects with description and type fields explaining what went wrong.
Update a scripted browser monitor
You can update an existing scripted browser monitor using the syntheticsUpdateScriptBrowserMonitor mutation. This allows you to modify the configuration of a scripted browser monitor that has already been created.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The unique entity GUID of the monitor you want to update. |
| Array | No | Browser(s) that the monitor will use to execute jobs. Supported browsers: |
| Array | No | Devices that the monitor will use to execute jobs. Supported devices: |
| Array | No | Array of public location identifiers where the monitor will run checks (e.g., |
| String | No | The updated display name for your scripted browser monitor. |
| Enum | No | How often the monitor runs. Options: |
| String | No | The runtime type used by your monitor. |
| String | No | The runtime type version used by your monitor. |
| String | No | The language used in your monitor. |
| String | No | The JavaScript code that the monitor executes. This should be plain text, not base64 encoded. |
| Enum | No | The monitor status. Options: |
| Boolean | No | Captures a screenshot during job execution when a failure occurs or a script is executed. |
| Float | No | The monitor's Apdex target in seconds, used to populate SLA reports. Defaults to 7.0 seconds. |
Sample request
mutation { syntheticsUpdateScriptBrowserMonitor( guid: ENTITY_GUID monitor: { browsers: [BROWSERS] devices: [DEVICES] locations: { public: ["LOCATION_1", "LOCATION_2"] } name: "MONITOR_NAME" period: PERIOD runtime: { runtimeType: "RUNTIME_TYPE" runtimeTypeVersion: "RUNTIME_TYPE_VERSION" scriptLanguage: "SCRIPT_LANGUAGE" } script: "SCRIPT_CONTENT" status: STATUS advancedOptions: { enableScreenshotOnFailureAndScript: ENABLE_SCREENSHOT } apdexTarget: APDEX_TARGET } ) { errors { description type } }}Sample response
A successful response returns null for errors:
{ "data": { "syntheticsUpdateScriptBrowserMonitor": { "errors": null } }}If there are any issues updating the monitor, the errors array will contain objects with description and type fields explaining what went wrong.
Upgrade a scripted browser monitor's runtime
You can upgrade a scripted browser monitor to use the newer Chrome 100+ runtime. This ensures your monitor uses the latest browser features and security updates.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The unique entity GUID of the monitor you want to upgrade. |
| String | Yes | The runtime type. |
| String | Yes | The runtime version. |
| String | Yes | The scripting language. |
Sample request
mutation { syntheticsUpdateScriptBrowserMonitor( guid: "ENTITY_GUID" monitor: { runtime: { runtimeType: "CHROME_BROWSER" runtimeTypeVersion: "100" scriptLanguage: "JAVASCRIPT" } } ) { errors { description type } }}Sample response
A successful response returns null for errors:
{ "data": { "syntheticsUpdateScriptBrowserMonitor": { "errors": null } }}If there are any issues upgrading the monitor runtime, the errors array will contain objects with description and type fields explaining what went wrong.
Downgrade a scripted browser monitor's runtime
You can downgrade a scripted browser monitor to use a legacy runtime. This may be necessary for compatibility reasons, but note that legacy runtimes will be end-of-life on October 22, 2024.
Important
Legacy runtimes are deprecated and will be end-of-life on October 22, 2024. Downgrading to legacy runtimes is not recommended except for temporary compatibility needs.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The unique entity GUID of the monitor you want to downgrade. |
| String | Yes | Set to empty string |
| String | Yes | Set to empty string |
| String | Yes | Set to empty string |
Sample request
mutation { syntheticsUpdateScriptBrowserMonitor( guid: "ENTITY_GUID" monitor: { runtime: { runtimeType: "", runtimeTypeVersion: "", scriptLanguage: "" } } ) { errors { description type } }}Sample response
A successful response returns null for errors:
{ "data": { "syntheticsUpdateScriptBrowserMonitor": { "errors": null } }}If there are any issues downgrading the monitor runtime, the errors array will contain objects with description and type fields explaining what went wrong.
Delete a scripted browser monitor
When a scripted browser monitor is no longer needed, you can permanently remove it using the syntheticsDeleteMonitor mutation.
To delete a monitor, refer to the Delete Synthetic monitor section.