0

I have a LWC with a button to download a list of records in a CSV file. My code is:

        const exportedFilename = 'issues.csv';
        if(navigator.msSaveBlob){
            navigator.msSaveBlob(blob, exportedFilename);
        } else if (navigator.userAgent.match(/iPhone|iPad|iPod/i)){
            const link = window.document.createElement('a')
            link.href='data:text/csv;charset=utf-8,' + encodeURI(blob);
            link.target="_blank"
            link.download=exportedFilename
            link.click()
        } else {
            const link = document.createElement("a")
            if(link.download !== undefined){
                const url = URL.createObjectURL(blob)
                link.setAttribute("href", url)
                link.setAttribute("download", exportedFilename)
                link.style.visibility='hidden'
                document.body.appendChild(link)
                link.click()
                document.body.removeChild(link)
            }
        }

Where doc is the variable where the data is formatted. It works fine in my scratch org, the problem is when I generate a managed package with this code and install it in another org. In that case, when you click the download button, the file downloaded is always empty and 0B and I have no idea why. Do you have any suggestion, please?

1 Answer 1

1

I'm not sure if you figured this out or not, but I am having the same issue. I finally found this answer posted in the trailblazer community. Based on the details provided, it sounds like you may be having the same issue since it was working in your scratch org.

Here's a link: https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4L8zSAF

1
  • 1
    To add to this in case that link ever goes away, it has to do with Lightning Web Security being enabled. If enabled, it will block certain content from being posted based on the MIME type.
    – Sean
    Commented Jul 30 at 2:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .