feat(client): add proxy object for request.agent for compatibility#1839
Merged
titanism merged 1 commit intoforwardemail:masterfrom Jan 6, 2026
Merged
Conversation
In node environments, the code in `node/agent.js` creates a proxy object around `Agent` so that it can be instantiated without using the `new` keyword. The equivalent code for the browser version (in `client.js`) defines `request.agent` as `() => new Agent()`. In supertest, the `TestAgent` attempts to subclass `Agent` with the call `Object.setPrototypeOf(TestAgent.prototype, Agent.prototype);`. This works in the node environment but not in the browser version, because in the browser version `() => new Agent()` is not an object and has an undefined prototype, leading to the error message `Object prototype may only be an Object or null: undefined`. Wrap `request.agent` in a proxy object for the client/browser case so that supertest can also use the library in browser contexts without error.
Contributor
Author
|
Fixes #1840 |
|
Any chance someone can look at this patch? This issue is making it trickier to keep all our testing libraries up-to-date (https://phabricator.wikimedia.org/T405027). |
Collaborator
|
v10.3.0 of superagent and v7.2.0 supertest published to npm with qs fixed https://github.com/forwardemail/superagent/releases/tag/v10.3.0 please consider supporting our maintenance efforts by becoming a @forwardemail user! sign up at https://forwardemail.net and use coupon code a few KB is not too bad for features that qs offers, it's maintained as well |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In node environments, the code in
node/agent.jscreates a proxy object aroundAgentso that it can be instantiated without using thenewkeyword. The equivalent code for the browser version (inclient.js) definesrequest.agentas() => new Agent().In supertest, the
TestAgentattempts to subclassAgentwith the callObject.setPrototypeOf(TestAgent.prototype, Agent.prototype);. This works in the node environment but not in the browser version, because in the browser version() => new Agent()is not an object and has an undefined prototype, leading to the error messageObject prototype may only be an Object or null: undefined.Wrap
request.agentin a proxy object for the client/browser case so that supertest can also use the library in browser contexts without error.Checklist