[bug]: Desktop post-request scripts fail when setting environment variables
Author: TrishadringCreated Sep 8, 2026Updated Sep 12, 2026
Is there an existing issue for this?
- I searched existing issues. This resembles #5475, but the problem is present in Desktop 26.1.2 and also affects the newer
hopp.env.active.setAPI.
Platform
Desktop App
Browser
Firefox
Operating System
macOS
Bug Description
What happened?
A POST request successfully returns a JSON response containing a string access_token. Attempting to save that value from the post-request script causes the script runner to display only:
Could not execute post-request script
There seems to be an error with post-request script. Please fix the errors and run tests again
The target environment variable remains empty and no test results execute. This occurs with both the legacy pw API and the experimental hopp API. The HTTP request itself succeeds with status 200 and returns valid JSON.
Steps to reproduce
- In the Desktop app, select an environment.
- Create an empty environment variable named
test_access_token. - Send a POST request whose response is JSON such as:
{ "access_token": "test-token" }
- Add this post-request script:
const token = pw.response.body.access_token;
pw.env.set("test_access_token", token);
pw.test("token stored", function () {
pw.expect(pw.env.get("test_access_token")).toBe(token);
});
- Run the request. The generic post-request script error appears and the variable is not set.
- The same behavior occurs with the experimental API:
const body = hopp.response.body.asJSON();
const token = body.access_token;
hopp.env.active.set("test_access_token", token);
hopp.test("token stored", () => {
hopp.expect(hopp.env.active.get("test_access_token")).toBe(token);
});
Expected behavior
The string response value should be stored in the active environment and available to subsequent requests. If the script cannot execute, the UI should show the underlying JavaScript/runtime error rather than only a generic message.
Additional context
- Interceptor: Native
- The response value is a string, not a number or object.
- A minimal legacy script using only
pw.env.set("test_access_token", "test-token")also fails. - Related issue #5475 reported a regression beginning in 25.9.0 and was closed, but this behavior is still reproducible in 26.1.2.
- Sensitive request URLs, credentials, client identifiers, and tokens have been omitted.
Deployment Type
Self-hosted (on-prem deployment)
Version
26.1.2 (26.1.2)
Source: hoppscotch/hoppscotch