mergeInto(LibraryManager.library, {
    SendVPSRequestToJS: function (urlPtr, jsonPtr, callbackIdPtr) {
        // Convert Unity strings to JavaScript strings
        var url = UTF8ToString(urlPtr);
        var jsonString = UTF8ToString(jsonPtr);
        var callbackId = UTF8ToString(callbackIdPtr);
        window.SendMessageToWeb(url + "|" + jsonString + "|" + callbackId)
    },
    DetectPlatform: function () {
        var userAgent = navigator.userAgent || navigator.vendor || window.opera;
    
        let result = "Unknown";
    
        if (/android/i.test(userAgent)) {
            if (window.ReactNativeWebView || window.JSInterface) {
                result = "Android WebView";
            } else {
                result = "Android Browser";
            }
        } else if (/iPad|iPhone|iPod/.test(userAgent) || /Macintosh/.test(userAgent)) {
            if (window.webkit && window.webkit.messageHandlers) {
                result = "iOS WebView";
            } else if (window.MKWebView || /MKWebView/i.test(userAgent)) {
                result = "iOS MKWebView";
            } else {
                result = "iOS Safari";
            }
        }
    
        // ✅ Use stringToNewUTF8 instead of allocate
        return stringToNewUTF8(result);
    }
    
});
