fix(browser): dedupe external scripts when api_host is a relative path (#4603)
findScript compared `script.src` against the url loadScript was given. `script.src` always reads back as a resolved absolute URL, but RequestRouter.endpointFor returns a relative url whenever api_host is a path such as "/ingest", because a relative host always falls into the CUSTOM region branch. The two never compared equal, so the dedupe never fired and every call to loadExternalDependency appended another <script> element for the same asset. The browser serves the extra copies from cache, so the network panel shows a single request and it is easy to miss. Measured on a production site behind a Next.js rewrite: 4 script elements for exception-autocapture.js and 3 for dead-clicks-autocapture.js, against one network request each. Compare the raw `src` attribute as well, which holds exactly what loadScript wrote. Resolving the incoming url instead would have been the other option, but the URL constructor is not allowed by the repo's compat lint rule (`URL is not supported in op_mini all`). The existing "does not add duplicate scripts" test already asserted this behaviour and passed only because its mock uses an absolute api_host. Added a sibling test with api_host "/ingest" that fails without this change, and reset api_host in beforeEach so the value cannot leak between tests.
F
François Martin committed
ca030a66bacd0f084845838e19c0f0b18d54e468
Parent: 9b2a1b1
Committed by GitHub <noreply@github.com>
on 8/23/2026, 7:12:44 AM