FileSaver.js icon indicating copy to clipboard operation
FileSaver.js copied to clipboard

fix: download file on SamsungBrowser with block auto download (fixes #660)

Open hudovisk opened this issue 5 years ago • 3 comments

SamsungBrowser has a settings enabled by default called "Block automatic downloads" that basically blocks all downloads that are not initiated by user interaction, thus making the call setTimeout(function () { click(a) }, 0) impossible to download a file on this browser, only if the user disables the settings option.

By checking the user agent for SamsungBrowser and calling click(a) instead of setTimeout(function () { click(a) }, 0) the function saveAs work as expected when called from an event initiated by the user. (button click)

Tested on SamsungBrowser 12.0.1.47 with a Smasung S6 SM-G920I.

Code used to test:

<html>
    <head>
        <script src="FileSaver.min.js"></script>
    </head>

    <body>
        <button onclick="download()">download</button>
        <script>
            var testCsv = "this,is,a,row\nthis,is,another,row";
            function download() {
                var blob = new Blob([testCsv], { type: 'text/csv;charset=utf-8;' });
                saveAs(blob, "test.csv")
            }
        </script>
    </body>
</html>

Fixes #660

hudovisk avatar Jul 11 '20 11:07 hudovisk

Pardon my question, but what is the purpose of the setTimeout with 0 milliseconds in the original code anyway?

lattam avatar Oct 30 '20 15:10 lattam

Hello any update on this? will this be released yet? Also does this really fix it? I guess not I have tried something similar locally and same result it fails to download while block automatic downloads is on.

MoeHamdan avatar May 03 '23 09:05 MoeHamdan

This needs to change to use window.open which works with Samsung Browser.. window.open(blob) though the file name will be lost but it will work.

MoeHamdan avatar May 04 '23 07:05 MoeHamdan