mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #5596] [MERGED] feat(scripting-revamp): add support for sending requests in scripting context #5274
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5274
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5596
Author: @jamesgeorge007
Created: 11/19/2025
Status: ✅ Merged
Merged: 11/26/2025
Merged by: @jamesgeorge007
Base:
next← Head:feat/updated-scripting-system📝 Commits (6)
3960262feat(scripting-revamp): add support for sending requests in scripting context2e301f2fix: address Cubic AI review feedbackeac120bchore: merge latest changes alongside conflict resolution573da10fix: address code review feedback for hopp.fetch implementation895f8aafix: address additional Cubic AI code review feedback022e2eachore: cleanup📊 Changes
70 files changed (+12934 additions, -1067 deletions)
View changed files
📝
packages/hoppscotch-cli/package.json(+2 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts(+548 -49)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/scripting-revamp-coll.json(+948 -119)➕
packages/hoppscotch-cli/src/__tests__/unit/hopp-fetch.spec.ts(+579 -0)➕
packages/hoppscotch-cli/src/utils/hopp-fetch.ts(+274 -0)📝
packages/hoppscotch-cli/src/utils/pre-request.ts(+4 -1)📝
packages/hoppscotch-cli/src/utils/request.ts(+28 -0)📝
packages/hoppscotch-cli/src/utils/test.ts(+5 -1)📝
packages/hoppscotch-common/locales/en.json(+7 -0)📝
packages/hoppscotch-common/src/components/MonacoScriptEditor.vue(+8 -1)📝
packages/hoppscotch-common/src/components/embeds/Request.vue(+13 -7)📝
packages/hoppscotch-common/src/components/http/Request.vue(+89 -30)📝
packages/hoppscotch-common/src/components/http/Response.vue(+10 -2)📝
packages/hoppscotch-common/src/components/http/ResponseMeta.vue(+15 -6)📝
packages/hoppscotch-common/src/components/http/TestResult.vue(+21 -4)📝
packages/hoppscotch-common/src/components/http/TestResultEntry.vue(+34 -3)📝
packages/hoppscotch-common/src/components/http/test/Response.vue(+13 -2)📝
packages/hoppscotch-common/src/components/lenses/ResponseBodyRenderer.vue(+4 -1)📝
packages/hoppscotch-common/src/helpers/RequestRunner.ts(+52 -71)➕
packages/hoppscotch-common/src/helpers/__tests__/hopp-fetch.spec.ts(+799 -0)...and 50 more files
📄 Description
This PR implements request-sending capabilities inside the scripting sandbox by introducing
hopp.fetch()and a globalfetch()(alias) with standards-aligned Fetch primitives (Request,Response,Headers,FormData,URLSearchParams), as proposed in #5221.Additionally, it adds support for
pm.sendRequest()for collections imported from Postman.It enables practical workflows such as OAuth token refresh, data lookups, chained API calls, and follow-up validations directly in pre-request and post-request scripts without leaving the scripting context. The implementation is designed for the QuickJS sandbox with proper marshalling across the VM boundary and predictable types for assertions and test reporting.
Related to #3305 #4558 HFE-319.
Usage
What’s Changed
hopp.fetch()and globalfetch()with standards-aligned primitives (Request,Response,Headers,FormData,URLSearchParams), enabling request-sending within scripts._bodyBytesnumeric arrays to safely cross the QuickJS VM boundary, avoiding invalid state after cage disposal..json(),.text(), and.arrayBuffer()matching platform behavior.getSetCookie()API for reliable multi-value Set-Cookie header extraction.KernelInterceptorServicerespecting the user's interceptor preference (Agent/Extension/Browser). At the same time, CLI uses axios withaxios-cookiejar-supportandtough-cookiefor automatic RFC 6265-compliant cookie management across redirects.pm.sendRequest()in both pre-request and post-request scripting contexts.pm.sendRequest()with error-first callback API for Postman compatibility, supporting both string URLs and request objects with header/body configuration.fetchcage module implemented in-house withinjs-sandboxfor the added use cases regarding asynchronous execution withfetch()calls, etc, that the module exposed from faraday-cage library has limited support for.FetchCallMeta(url, method, timestamp) andHoppFetchHooktypes, integrating fetch operations into script runner options.1375and1378suppressed to prevent false "top-level await in non-module" errors.hasCookieBasedAuthplatform feature flag.ECONNRESET/DNSfailures with graceful skip on persistent errors.testResultsto null on request start, ensuring a clean state between runs.pwnamespace and existing scripts unchanged.Reviewer Map (Touched Areas)
packages/hoppscotch-js-sandboxsrc/cage-modules/custom-fetch.ts: Core Fetch implementation, marshalling, single-consumption enforcement.src/cage-modules/scripting-modules.ts: Module exposure, lifecycle, hook registration.src/web/pre-request/index.ts&src/node/pre-request/index.ts: Early-return on error; success-only capture semantics.src/web/test-runner/index.ts&src/node/test-runner/experimental.ts: Error propagation as Left for test failures.src/bootstrap-code/pre-request.js&post-request.js: Fetch exposure in sandbox; pm.sendRequest wrapper.src/__tests__/fetch/*&src/__tests__/hopp-namespace/fetch.spec.ts: Coverage across API and edge cases.packages/hoppscotch-commonsrc/helpers/hopp-fetch.ts: Web app fetch hook routing through KernelInterceptorService.src/helpers/RequestRunner.ts: Fetch hook creation and injection into script context.src/components/http/Request.vue: Reset testResults at send to remove flicker.src/components/MonacoScriptEditor.vue: ES2022 target, top-level await support, diagnostic suppression.src/services/scripting-interceptor-inspector.service.ts: Inspector tracking fetch calls, CSRF/interceptor warnings.packages/hoppscotch-clisrc/utils/hopp-fetch.ts: CLI fetch hook with axios + cookie jar integration.src/utils/pre-request.ts&src/utils/test.ts: Fetch hook creation and injection.src/__tests__/e2e/commands/test.spec.ts: Network retry logic for snapshot tests.src/__tests__/e2e/fixtures/collections/scripting-revamp-coll.json: E2E test collection with fetch operations.Notes to Reviewers
fetchandhopp.fetchmethod behaviours via the collection as part of the CLI e2e test suite.Import the Postman collection here to validate the
pm.sendRequest()method behaviors.Test same-origin fetch with cookie auth to see CSRF warning; test Extension/Proxy interceptor usage to see compatibility warning.
Summary by cubic
Adds request-sending to the scripting sandbox with hopp.fetch(), global fetch(), and pm.sendRequest so pre/post-request scripts can perform token refreshes, chained calls, and validations. Requests respect the chosen interceptor across web, desktop, and CLI, with strong typing and extensive tests.
New Features
Bug Fixes
Written for commit
022e2eadda. Summary will update automatically on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.