[PR #5090] [MERGED] feat: migrate to a unified scripting system based on faraday-cage #5052

Closed
opened 2026-03-17 02:32:11 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5090
Author: @jamesgeorge007
Created: 5/21/2025
Status: Merged
Merged: 5/23/2025
Merged by: @jamesgeorge007

Base: nextHead: feat/unify-scripting-with-fadaray-cage


📝 Commits (6)

  • b3afdda feat: migrate to a unified scripting system based on faraday-cage
  • 06f35d7 fix(desktop): csp override for faraday-cage
  • dc20a29 fix: handle deserialization of Date strings in sandbox context
  • c8c10a0 docs: update CLI README.md
  • 11c10cb chore: formatting updates
  • b23bdb5 chore: bump CLI version

📊 Changes

51 files changed (+2122 additions, -659 deletions)

View changed files

📝 packages/hoppscotch-cli/README.md (+51 -31)
📝 packages/hoppscotch-cli/package.json (+1 -1)
📝 packages/hoppscotch-cli/src/__tests__/e2e/commands/__snapshots__/test.spec.ts.snap (+2 -2)
📝 packages/hoppscotch-cli/src/__tests__/functions/mutators/parseCollectionData.spec.ts (+1 -3)
📝 packages/hoppscotch-cli/src/commands/test.ts (+11 -2)
📝 packages/hoppscotch-cli/src/index.ts (+1 -0)
📝 packages/hoppscotch-cli/src/interfaces/response.ts (+1 -0)
📝 packages/hoppscotch-cli/src/options/test/delay.ts (+4 -4)
📝 packages/hoppscotch-cli/src/types/collections.ts (+1 -0)
📝 packages/hoppscotch-cli/src/types/commands.ts (+1 -0)
📝 packages/hoppscotch-cli/src/types/request.ts (+1 -0)
📝 packages/hoppscotch-cli/src/utils/collections.ts (+15 -4)
📝 packages/hoppscotch-cli/src/utils/display.ts (+3 -1)
📝 packages/hoppscotch-cli/src/utils/functions/array.ts (+1 -1)
📝 packages/hoppscotch-cli/src/utils/pre-request.ts (+8 -4)
📝 packages/hoppscotch-cli/src/utils/request.ts (+5 -3)
📝 packages/hoppscotch-cli/src/utils/test.ts (+13 -5)
📝 packages/hoppscotch-common/locales/en.json (+5 -0)
📝 packages/hoppscotch-common/package.json (+3 -2)
📝 packages/hoppscotch-common/src/components.d.ts (+3 -0)

...and 31 more files

📄 Description

The pre-existing scripting system is powered by a web worker-based sandbox implementation for browser platforms and the Node.js target is powered by isolated-vm for the CLI. This PR aims to migrate the existing system powering scripting to a unified implementation backed by the in-house library faraday-cage built on top of QuickJS.

There is a user-facing addition as part of the experimental scripting sandbox implementation with an in-app console supporting the basic methods like log, debug, info, warn and error. All console methods are supported in the scripting context and will continue to be recorded in the dev tools console. Non-primitive values will be rendered in a tree viewer. The response section (scoped per request) will have a new tab where the log entries will be rendered. In the context of the collection runner, this would be displayed in the response section when selecting a request to view its response. Logs will appear beneath every request on the CLI.

The new scripting implementation will be the default going ahead with the ability to opt out via the settings page on web platforms and the --legacy-scripting flag on the CLI.

Closes HFE-830.

Preview

image
image

Non primitive logs

image

Collection runner

image

Settings addition

image

What's changed

  • Migrate the existing scripting implementation powered by web worker-based implementation on browser platforms and isolated-vm on Node.js to a unified implementation on top of faraday-cage.
  • Component additions for the in-app console renderer.
  • Introduce an Experimental scripting sandbox option under settings on the web app and a new --legacy-scripting CLI flag to toggle between the experimental and legacy scripting implementations.
  • Web worker-based implementation on the app side consuming the new scripting implementation. The pre-existing implementation had the same housed within the js-sandbox package.
  • REST tabs now have a consoleEntries field addition keeping track of the console entries per request.
  • vue-json-pretty is added as a dependency powering the tree viewer in the in-app console renderer.
  • faraday-cage dependency addition under js-sandbox.
  • Test suite/snapshot additions, bundler config tweaks to support worker-based implementation on the app side, etc.
  • Documentation updates on the CLI, prettifying the codebase and version bumps.

Notes to reviewers

  • Perform sanity testing over pre-request and post-request scripts. Ensure the behaviour stays consistent in the legacy implementation.
  • Try script combinations with fetch, crypto, etc.
  • For the web app, give it a try on different console logging combinations and observe the results; keep an eye out for non-primitives and persistence of logs.
  • The pre-existing implementation didn't produce logs on the CLI; observe logs appearing beneath each request with the new implementation.
  • Toggle between experimental and legacy implementations via the settings page on the web app and CLI flag addition.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5090 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 5/21/2025 **Status:** ✅ Merged **Merged:** 5/23/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `feat/unify-scripting-with-fadaray-cage` --- ### 📝 Commits (6) - [`b3afdda`](https://github.com/hoppscotch/hoppscotch/commit/b3afddaca28c58e0255bc3aba448dc9e9ae6541b) feat: migrate to a unified scripting system based on `faraday-cage` - [`06f35d7`](https://github.com/hoppscotch/hoppscotch/commit/06f35d7b19d9c44022b9f58d2cf216e394f39e59) fix(desktop): csp override for `faraday-cage` - [`dc20a29`](https://github.com/hoppscotch/hoppscotch/commit/dc20a29de31a9d3ffa07c5db98af36d1f92e8f0a) fix: handle deserialization of `Date` strings in sandbox context - [`c8c10a0`](https://github.com/hoppscotch/hoppscotch/commit/c8c10a01af7455a01056718234fb3d4ceada758a) docs: update CLI `README.md` - [`11c10cb`](https://github.com/hoppscotch/hoppscotch/commit/11c10cbc4d03c5459b4952b96e0590b7e4c2d31a) chore: formatting updates - [`b23bdb5`](https://github.com/hoppscotch/hoppscotch/commit/b23bdb58985abcdd4ad6083a7bc3da41279caa36) chore: bump CLI version ### 📊 Changes **51 files changed** (+2122 additions, -659 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-cli/README.md` (+51 -31) 📝 `packages/hoppscotch-cli/package.json` (+1 -1) 📝 `packages/hoppscotch-cli/src/__tests__/e2e/commands/__snapshots__/test.spec.ts.snap` (+2 -2) 📝 `packages/hoppscotch-cli/src/__tests__/functions/mutators/parseCollectionData.spec.ts` (+1 -3) 📝 `packages/hoppscotch-cli/src/commands/test.ts` (+11 -2) 📝 `packages/hoppscotch-cli/src/index.ts` (+1 -0) 📝 `packages/hoppscotch-cli/src/interfaces/response.ts` (+1 -0) 📝 `packages/hoppscotch-cli/src/options/test/delay.ts` (+4 -4) 📝 `packages/hoppscotch-cli/src/types/collections.ts` (+1 -0) 📝 `packages/hoppscotch-cli/src/types/commands.ts` (+1 -0) 📝 `packages/hoppscotch-cli/src/types/request.ts` (+1 -0) 📝 `packages/hoppscotch-cli/src/utils/collections.ts` (+15 -4) 📝 `packages/hoppscotch-cli/src/utils/display.ts` (+3 -1) 📝 `packages/hoppscotch-cli/src/utils/functions/array.ts` (+1 -1) 📝 `packages/hoppscotch-cli/src/utils/pre-request.ts` (+8 -4) 📝 `packages/hoppscotch-cli/src/utils/request.ts` (+5 -3) 📝 `packages/hoppscotch-cli/src/utils/test.ts` (+13 -5) 📝 `packages/hoppscotch-common/locales/en.json` (+5 -0) 📝 `packages/hoppscotch-common/package.json` (+3 -2) 📝 `packages/hoppscotch-common/src/components.d.ts` (+3 -0) _...and 31 more files_ </details> ### 📄 Description The pre-existing scripting system is powered by a web worker-based sandbox implementation for browser platforms and the Node.js target is powered by [isolated-vm](https://github.com/laverdet/isolated-vm) for the CLI. This PR aims to migrate the existing system powering scripting to a unified implementation backed by the in-house library [faraday-cage](https://github.com/AndrewBastin/faraday-cage) built on top of [QuickJS](https://github.com/justjake/quickjs-emscripten). There is a user-facing addition as part of the experimental scripting sandbox implementation with an in-app console supporting the basic methods like `log`, `debug`, `info`, `warn` and `error`. All `console` methods are supported in the scripting context and will continue to be recorded in the dev tools console. Non-primitive values will be rendered in a tree viewer. The response section (scoped per request) will have a new tab where the log entries will be rendered. In the context of the collection runner, this would be displayed in the response section when selecting a request to view its response. Logs will appear beneath every request on the CLI. The new scripting implementation will be the default going ahead with the ability to opt out via the settings page on web platforms and the `--legacy-scripting` flag on the CLI. Closes HFE-830. ### Preview <img width="1095" alt="image" src="https://github.com/user-attachments/assets/2cfc8b6e-ad8f-44b2-8165-ccb52aaea186" /> ------- <img width="1093" alt="image" src="https://github.com/user-attachments/assets/6121f265-b434-4eaf-b39a-b55f4bdf26c4" /> -------- > #### Non primitive logs <img width="1091" alt="image" src="https://github.com/user-attachments/assets/071975a3-2d2d-43c7-9364-327c3b0b13e2" /> -------- > #### Collection runner <img width="1088" alt="image" src="https://github.com/user-attachments/assets/470156fe-b293-4cb3-b05f-21bdd49b36b6" /> -------- > #### Settings addition ![image](https://github.com/user-attachments/assets/038ef834-f784-459d-abb5-c1bde5eb2235) ### What's changed - Migrate the existing scripting implementation powered by web worker-based implementation on browser platforms and [isolated-vm](https://github.com/laverdet/isolated-vm) on Node.js to a unified implementation on top of `faraday-cage`. - Component additions for the in-app console renderer. - Introduce an `Experimental scripting sandbox` option under settings on the web app and a new `--legacy-scripting` CLI flag to toggle between the experimental and legacy scripting implementations. - Web worker-based implementation on the app side consuming the new scripting implementation. The pre-existing implementation had the same housed within the `js-sandbox` package. - REST tabs now have a `consoleEntries` field addition keeping track of the console entries per request. - [vue-json-pretty](https://github.com/leezng/vue-json-pretty) is added as a dependency powering the tree viewer in the in-app console renderer. - `faraday-cage` dependency addition under `js-sandbox`. - Test suite/snapshot additions, bundler config tweaks to support worker-based implementation on the app side, etc. - Documentation updates on the CLI, prettifying the codebase and version bumps. ### Notes to reviewers - Perform sanity testing over pre-request and post-request scripts. Ensure the behaviour stays consistent in the legacy implementation. - Try script combinations with `fetch`, `crypto`, etc. - For the web app, give it a try on different console logging combinations and observe the results; keep an eye out for non-primitives and persistence of logs. - The pre-existing implementation didn't produce logs on the CLI; observe logs appearing beneath each request with the new implementation. - Toggle between experimental and legacy implementations via the settings page on the web app and CLI flag addition. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:32:11 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5052
No description provided.