Skip to content

Conversation

@codders
Copy link
Contributor

@codders codders commented Aug 12, 2025

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.

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

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.
@codders
Copy link
Contributor Author

codders commented Aug 12, 2025

Fixes #1840

@AaronSchulz
Copy link

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).

@titanism titanism merged commit a488d25 into forwardemail:master Jan 6, 2026
2 checks passed
@titanism
Copy link
Collaborator

titanism commented Jan 6, 2026

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
https://github.com/forwardemail/supertest/releases/tag/v7.2.0

please consider supporting our maintenance efforts by becoming a @forwardemail user! sign up at https://forwardemail.net and use coupon code GITHUB for 100% off 🙏

a few KB is not too bad for features that qs offers, it's maintained as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants