Emulate sendBeacon if beacon.enabled is disabled in Firefox for https://*.perplexity.ai/*
This userscript emulates the navigator.sendBeacon method on websites under the https://.perplexity.ai/ domain. In recent Firefox versions, when the internal beacon.enabled setting is disabled, the native sendBeacon method does not function, causing issues with site features relying on it to send data asynchronously in the background.
The script overrides navigator.sendBeacon by using the modern fetch API with the keepalive: true option, closely mimicking the behavior of the original sendBeacon. This allows sending asynchronous POST requests without blocking page unload and with a high probability that data will be sent when the tab or page closes.
fetch with keepaliveFirefox sometimes disables the Beacon API by default (when beacon.enabled is false), breaking functionality on sites relying on sendBeacon for analytics, logging, or telemetry. This script locally emulates sendBeacon on the site level, restoring functionality without compromising security or requiring user intervention in browser configuration.
sendBeacon method will work correctly even if disabled by the browser.This script is open source and contains no malicious code. The full source code is available for review before installation. It does not load external resources or send data to third parties.