Brave Browser Crashes Blazor App after file download

After downloading an image from Blazor It crashes the blazor application after download.

To Reproduce:

Nuget Package: QRCoder 1.4.1

C# Code:


private async Task DownloadFileFromStream()
    {
        using (CancellationTokenSource source = new CancellationTokenSource())
        {
            var arr = ImageToByte(await GetQRCodeBitmap(StoreId, source.Token));
            MemoryStream fileStream = new MemoryStream(arr);
            string fileName = "QRCode.png";
            using var streamRef = new DotNetStreamReference(stream: fileStream);
            await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
        }
    }

public async Task<Bitmap> GetQRCodeBitmap(string storeId, CancellationToken cancellationToken)
        {
            return await Task.Run(() =>
            {
                using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
                using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(storeId, QRCodeGenerator.ECCLevel.L))
                using (QRCode qrCode = new QRCode(qrCodeData))
                {
                    Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.Transparent, false);
                    return qrCodeImage;
                }
            }, cancellationToken);
        }

JavaScript Code:

async function downloadFileFromStream(fileName, contentStreamReference) {
            const arrayBuffer = await contentStreamReference.arrayBuffer();
            const blob = new Blob([arrayBuffer]);
            const url = URL.createObjectURL(blob);

            triggerFileDownload(fileName, url);

            URL.revokeObjectURL(url);
        }

        function triggerFileDownload(fileName, url) {
            const anchorElement = document.createElement('a');
            anchorElement.href = url;
            anchorElement.download = fileName ?? '';
            anchorElement.click();
            anchorElement.remove();
        }

Hello @Cornelis1

Thank you for reaching out and sorry to hear you’re having trouble with Brave. Please try to open a new page using private mode or guest mode.

You can open a Guest Window by going to Main menu --> Open Guest window.

Let me know if that works and have a great day!