As mentioned in https://github.com/WICG/pending-beacon/issues/17#issuecomment-1202101055, the URL that Pending*Beacon(url) constructor or setURL(url) gets are always parsed into string literal, even if its value is null or undefined, i.e. they get converted to 'null' or 'undefined'. The URL constructed then becomes https://example.com/null for beacons on https://example.com.
This behavior is caused by the IDL definition that inherits from navigator.sendBeacon():
USVString should be USVString? to allow null/undefined values.
I guess the original intention is to make url non-optional. But converting null to string just seems wrong. We are also unsure about how many users rely on this behavior when using navigator.sendBeacon().
In PendingBeacon's case, there is a discussion around whether to allow constructing a beacon first (without an explicit URL), and updating its URL later. The current API is already kinds of supporting this behavior with setURL(), except that when users trying to construct one with url=null, they gets an unexpected https://example.com/null instead.
To update PendingBeacon to not have this behavior, the explainer also needs to specify one of the following options:
The browser must not send out beacons without a URL set.
OR Pending*Beacon() throws TypeError on getting null/undefined URL.
As mentioned in https://github.com/WICG/pending-beacon/issues/17#issuecomment-1202101055, the URL that
Pending*Beacon(url)
constructor orsetURL(url)
gets are always parsed into string literal, even if its value isnull
orundefined
, i.e. they get converted to'null'
or'undefined'
. The URL constructed then becomeshttps://example.com/null
for beacons onhttps://example.com
.This behavior is caused by the IDL definition that inherits from
navigator.sendBeacon()
:USVString
should beUSVString?
to allownull
/undefined
values.I guess the original intention is to make
url
non-optional. But converting null to string just seems wrong. We are also unsure about how many users rely on this behavior when usingnavigator.sendBeacon()
.In
PendingBeacon
's case, there is a discussion around whether to allow constructing a beacon first (without an explicit URL), and updating its URL later. The current API is already kinds of supporting this behavior withsetURL()
, except that when users trying to construct one with url=null, they gets an unexpectedhttps://example.com/null
instead.To update
PendingBeacon
to not have this behavior, the explainer also needs to specify one of the following options:Pending*Beacon()
throws TypeError on getting null/undefined URL.