fix: fall back to fetch when sendBeacon payload exceeds 64 KB limit#777
Open
TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
Open
fix: fall back to fetch when sendBeacon payload exceeds 64 KB limit#777TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
Conversation
navigator.sendBeacon silently fails when the payload exceeds ~65 KB. Add a proactive size check in DataPlaneClient.sendBeacon that rejects before presigning when the serialized body exceeds 64,000 bytes, allowing the existing catch handler to fall back to fetch. Resolves aws-observability#761
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.
Resolves #761
Problem
navigator.sendBeaconhas a payload size limit of approximately 64 KiB on most modern browsers. When the serialized event batch exceeds this limit,sendBeaconsilently returnsfalse, causing the request to be dropped. While the existing code does catch beacon failures and fall back tofetch, the failure only occurs after the (potentially expensive) request presigning step has already completed — wasting time during a critical window like page unload.Solution
Add a proactive payload size check in
DataPlaneClient.sendBeaconthat rejects immediately when the serialized body exceeds 64,000 bytes (a conservative threshold below the 64 KiB browser limit to avoid edge-case variance across browsers). This lets the existing.catch()fallback inDispatch.dispatchBeaconandflushSyncroute the request throughfetchwithout wasting time on presigning a request that would fail anyway.The size is measured with
new Blob([serializedRequest]).sizeto correctly account for multi-byte characters.Changes
src/dispatch/DataPlaneClient.ts— AddedBEACON_PAYLOAD_LIMITconstant (64,000 bytes) and a size guard at the top ofsendBeaconthat rejects before presigning when the payload is too large.src/dispatch/__tests__/DataPlaneClient.test.ts— Added two tests: one verifying that oversized payloads are rejected (and the beacon handler is never called), and one confirming normal-sized payloads still go through beacon as before.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.