PDF Auto-Print Fails: Sandbox and CORS Issues

Hi, I’m using apitemplate through Retool to create PDF documents.
I send a POST request (create_pdf) to apitemplate with JSON in the body and receive the following response:

Example Response:

{
 "download_url": "https://s3.ap-southeast-1.amazonaws.com/pub-cdn.apitemplate.io/2024/10/f3bb5ba0-a055-48e9-93c9-eb23377b4d37.pdf",
 "transaction_ref": "f3bb5ba0-a055-48e9-93c9-eb23377b4d37",
 "total_pages": 9,
 "status": "success",
 "template_id": "1a477b23ba5009d8"
}

I’m trying to open the PDF in a new tab and automatically trigger the print dialog with this code:

const pdfUrl = create_pdf.data.download_url;
const printWindow = window.open(pdfUrl);

if (printWindow) {
  printWindow.focus();
  printWindow.onload = function() {
    printWindow.print();
  };
}

However, the print window doesn’t open, and I receive the following error:

Blocked opening 'https://s3.ap-southeast-1.amazonaws.com/...pdf' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.

Is there a way to deal with this sandboxing issue in Retool, and is it possible to automatically open the print dialog in this case?

Hi @shir_Indaporker,

All JS in Retool is run in a sandbox, so a lot of window functions will not be able to escape out. Some users will use a custom component to get around this limitation. window.print() will not work in a JS query, but you should be able to get it to print the contents of a custom component when run in a custom component's script.

Otherwise, I know some folks have explored third party printing solutions - Tutorial: Making PDF's in Retool