<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Downloading blocked by CSP in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/261972#M1140</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;In a custom App, I retrieve some JSON content from an API, and I want the user to be able to download a JSON file of this data.&lt;/P&gt;&lt;P&gt;I tried a few things like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  const downloadTxtFile = () =&amp;gt; {
  const texts = ["line 1", "line 2", "line 3"]// file object
  const file = new Blob(texts, { type: 'text/plain' });// anchor link
  const element = document.createElement("a");
  element.href = URL.createObjectURL(file);
  element.download = "100ideas-" + Date.now() + ".txt";// simulate link click
  document.body.appendChild(element); // Required for this to work in FireFox
  element.click();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But each time I got a CSP error :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Content-Security-Policy : Les paramètres de la page ont empêché le chargement d’une ressource (frame-src) à l’adresse blob:http://localhost:3000/c967a477-517c-4a45-b661-0db72d23a37a car elle enfreint la directive suivante : « frame-src 'self' https://{environmentid}.live.dynatrace.com https://sso.dynatrace.com https://chat-one.dynatrace.com https://dev.access-approval.internal.dynatracelabs.com https://hardening.access-approval.internal.dynatracelabs.com https://access-approval.internal.dynatrace.com http://localhost:3000 »&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to change the CSP rules, but it didn't work and according to &lt;A href="https://developer.dynatrace.com/develop/security/configure-csp-rules/" target="_self"&gt;this&lt;/A&gt; it might not be possible to change frame-src.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an alternative approach to allow file downloads without running into CSP restrictions?&lt;/P&gt;</description>
    <pubDate>Fri, 08 Nov 2024 14:06:15 GMT</pubDate>
    <dc:creator>Auriane</dc:creator>
    <dc:date>2024-11-08T14:06:15Z</dc:date>
    <item>
      <title>Downloading blocked by CSP</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/261972#M1140</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;In a custom App, I retrieve some JSON content from an API, and I want the user to be able to download a JSON file of this data.&lt;/P&gt;&lt;P&gt;I tried a few things like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  const downloadTxtFile = () =&amp;gt; {
  const texts = ["line 1", "line 2", "line 3"]// file object
  const file = new Blob(texts, { type: 'text/plain' });// anchor link
  const element = document.createElement("a");
  element.href = URL.createObjectURL(file);
  element.download = "100ideas-" + Date.now() + ".txt";// simulate link click
  document.body.appendChild(element); // Required for this to work in FireFox
  element.click();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But each time I got a CSP error :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Content-Security-Policy : Les paramètres de la page ont empêché le chargement d’une ressource (frame-src) à l’adresse blob:http://localhost:3000/c967a477-517c-4a45-b661-0db72d23a37a car elle enfreint la directive suivante : « frame-src 'self' https://{environmentid}.live.dynatrace.com https://sso.dynatrace.com https://chat-one.dynatrace.com https://dev.access-approval.internal.dynatracelabs.com https://hardening.access-approval.internal.dynatracelabs.com https://access-approval.internal.dynatrace.com http://localhost:3000 »&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to change the CSP rules, but it didn't work and according to &lt;A href="https://developer.dynatrace.com/develop/security/configure-csp-rules/" target="_self"&gt;this&lt;/A&gt; it might not be possible to change frame-src.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an alternative approach to allow file downloads without running into CSP restrictions?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 14:06:15 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/261972#M1140</guid>
      <dc:creator>Auriane</dc:creator>
      <dc:date>2024-11-08T14:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Downloading blocked by CSP</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/262056#M1145</link>
      <description>&lt;P&gt;Hi Auriane,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll update you soon with a better answer. For now, can you try to do&lt;SPAN&gt;&amp;nbsp;a workaround which is to create an iframe with a download link instead of having it in the main document:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Some explanation: &lt;A href="https://github.com/Shopify/shopify-app-bridge/issues/11#issuecomment-710605337" target="_blank" rel="noopener"&gt;https://github.com/Shopify/shopify-app-bridge/issues/11#issuecomment-710605337&lt;/A&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function downloadBlobFile(file) {
const blobUrl = URL.createObjectURL(file);

const iframe = document.createElement('iframe');

iframe.style.display = 'none';

iframe.addEventListener('load', () =&amp;gt; {

const a = iframe.contentDocument.createElement('a');

a.href = blobUrl;
a.download = file.name;

iframe.contentDocument.body.appendChild(a);

a.click();
})

document.body.appendChild(iframe);

setTimeout(() =&amp;gt; {
document.body.removeChild(iframe);
}, 1000);
}

const file = new File(['Hello, world!'], "aaa.json",{type: 'application/json'});
downloadBlobFile(file);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2024 12:44:34 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/262056#M1145</guid>
      <dc:creator>haris</dc:creator>
      <dc:date>2024-11-11T12:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Downloading blocked by CSP</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/262134#M1150</link>
      <description>&lt;P&gt;It works !&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 09:05:38 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Downloading-blocked-by-CSP/m-p/262134#M1150</guid>
      <dc:creator>Auriane</dc:creator>
      <dc:date>2024-11-12T09:05:38Z</dc:date>
    </item>
  </channel>
</rss>

