Emulate sendBeacon on Perplexity.ai

Emulate sendBeacon if beacon.enabled is disabled in Firefox for https://*.perplexity.ai/*

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Emulate sendBeacon on Perplexity.ai
// @namespace    http://tampermonkey.net/
// @author       ohmylock
// @version      1.0
// @description  Emulate sendBeacon if beacon.enabled is disabled in Firefox for https://*.perplexity.ai/*
// @match        https://*.perplexity.ai/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Переопределяем navigator.sendBeacon для сайта, если это нужно
    if (!navigator.sendBeacon) {
        navigator.sendBeacon = function(url, data) {
            try {
                fetch(url, {
                    method: 'POST',
                    body: data,
                    keepalive: true,
                    credentials: 'include', // если нужен куки
                    headers: {
                        // Если данные в формате Blob или FormData, можно не указывать
                        // 'Content-Type': 'application/x-www-form-urlencoded' // при необходимости
                    }
                });
                return true;
            } catch (e) {
                return false;
            }
        };
    }
})();