Only Partial PDF is visible in Edge with CSP nonce.

Pottumuttu, Vasuprada 30 Reputation points
2026-07-15T11:01:10.9233333+00:00

Only Partial PDF is rendered in edge with CSP nonce. Edge supports CSP2 but still getting this issue.

In chrome it renders completely as expected. Use the below HTML to replicate the issue.User's image

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />

    <meta
      http-equiv="Content-Security-Policy"
      content="
            default-src 'self';
            script-src 'nonce-testNonce123';
            style-src 'nonce-testNonce123';
            img-src 'self' data: blob:;
            object-src 'none';
            frame-ancestors 'self';
          "
    />

    <title>PDF Upload CSP Test</title>

    <style nonce="testNonce123">
      body {
        font-family: Arial, sans-serif;
        padding: 30px;
      }

      .container {
        display: flex;
        flex-direction: column;
        gap: 12px;
        max-width: 500px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h2>PDF Upload Test</h2>

      <input type="file" id="pdfInput" accept="application/pdf" />

      <button id="openBtn">Open PDF in New Tab</button>

      <div id="status"></div>
    </div>

    <script nonce="testNonce123">
      document.getElementById("openBtn").addEventListener("click", () => {
        const fileInput = document.getElementById("pdfInput");

        if (!fileInput.files.length) {
          alert("Select a PDF first");
          return;
        }

        const pdfFile = fileInput.files[0];

        console.log("Selected PDF:", pdfFile);

        const blobUrl = URL.createObjectURL(pdfFile);

        console.log("Blob URL:", blobUrl);

        document.getElementById("status").textContent =
          "Opening PDF: " + blobUrl;

        window.open(blobUrl, "_blank");
      });
    </script>
  </body>
</html>

Microsoft Edge | Read PDFs | MacOS
0 comments No comments

Answer accepted by question author
Thomas4-N 21,930 Reputation points Microsoft External Staff Moderator
2026-07-16T07:58:58.32+00:00

Hello Pottumuttu, Vasuprada,

This appears to match an open Edge issue where a strict nonce-based style-src causes the built-in PDF viewer to render incompletely or lose its toolbar. The same behavior has been reproduced with PDF blob: URLs and does not occur in Chrome

https://github.com/MicrosoftEdge/DevTools/issues/427

The reported workaround is to allow the specific inline-style hashes used by Edge through unsafe-hashes. If changing the CSP is not acceptable, using a separate PDF renderer such as PDF.js may be an alternative, but its scripts, styles, worker, and CDN domain must also be explicitly permitted by your CSP.

I would also recommend adding your reproduction details to the existing Edge bug report and submitting feedback through Edge > ... > Help and feedback > Send feedback.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Senthil kumar 2,420 Reputation points
    2026-07-15T11:40:36.54+00:00

    Hi @Pottumuttu, Vasuprada

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Open PDF in New Tab (PDF.js — Edge-safe)</title>
      <style>
        body { font-family: system-ui, Arial, sans-serif; margin: 40px; line-height: 1.5; }
        h1 { font-size: 1.3rem; }
        .row { margin: 16px 0; }
        button { padding: 8px 16px; font-size: 1rem; cursor: pointer; }
        #status { margin-top: 12px; color: #555; }
        .hint { background:#eef; padding:12px 16px; border-radius:6px; font-size:.9rem; }
        code { background:#e4e4e4; padding:1px 5px; border-radius:3px; }
      </style>
    </head>
    <body>
      <h1>Open PDF in a new tab (rendered with PDF.js)</h1>
      <p class="hint">
        The new tab renders every page with PDF.js instead of Edge's built-in PDF viewer, so the
        partial-render bug can't happen. Serve this over <code>http://localhost:8000</code>
        (e.g. <code>python -m http.server 8000</code>) — not by double-clicking the file.
      </p>
      <div class="row">
        <input type="file" id="pdfInput" accept="application/pdf" />
        <button id="openBtn">Open PDF in new tab</button>
      </div>
      <div id="status"></div>
      <script type="module">
        const fileInput = document.getElementById("pdfInput");
        const status = document.getElementById("status");
        // HTML that will run INSIDE the new tab. It reads the ArrayBuffer we hand it
        // (window.__PDF_DATA__) and renders each page to a canvas with PDF.js.
        const viewerHtml = `<!DOCTYPE html>
    <html lang="en"><head><meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>PDF</title>
    <style>
      body{margin:0;background:#525659;}
      #status{color:#fff;font-family:system-ui,Arial,sans-serif;padding:10px 14px;}
      canvas{display:block;margin:0 auto 12px;max-width:100%;box-shadow:0 1px 6px rgba(0,0,0,.5);background:#fff;}
    </style></head>
    <body>
      <div id="status">Loading…</div>
      <div id="pages"></div>
      <script type="module">
        import * as pdfjsLib from "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.4.168/pdf.min.mjs";
        pdfjsLib.GlobalWorkerOptions.workerSrc =
          "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.4.168/pdf.worker.min.mjs";
        const s = document.getElementById("status");
        const pagesEl = document.getElementById("pages");
        (async () => {
          try {
            const raw = window.__PDF_DATA__;
            if (!raw) { s.textContent = "No PDF data received."; return; }
            // Copy the bytes into THIS tab's own realm — an ArrayBuffer created in
            // the opener tab isn't recognized by PDF.js here, which causes the
            // "Invalid PDF binary data" error. .slice() gives a fresh local buffer.
            const data = new Uint8Array(raw).slice();
            const pdf = await pdfjsLib.getDocument({ data }).promise;
            s.textContent = "Rendering " + pdf.numPages + " page(s)…";
            const scale = 1.5;
            for (let n = 1; n <= pdf.numPages; n++) {
              const page = await pdf.getPage(n);
              const vp = page.getViewport({ scale });
              const c = document.createElement("canvas");
              const ctx = c.getContext("2d");
              c.width = vp.width; c.height = vp.height;
              pagesEl.appendChild(c);
              await page.render({ canvasContext: ctx, viewport: vp }).promise;
            }
            s.textContent = pdf.numPages + " page(s)";
            setTimeout(() => s.remove(), 1500);
          } catch (e) { s.textContent = "Error: " + e.message; }
        })();
      <\/script>
    </body></html>`;
        document.getElementById("openBtn").addEventListener("click", async () => {
          if (!fileInput.files.length) { alert("Select a PDF first"); return; }
          status.textContent = "Opening…";
          const data = await fileInput.files[0].arrayBuffer();
          const win = window.open("", "_blank");
          if (!win) { status.textContent = "Pop-up blocked — allow pop-ups."; return; }
          // Same-origin new tab: hand it the ArrayBuffer by reference, then write the page.
          win.__PDF_DATA__ = data;
          win.document.open();
          win.document.write(viewerHtml);
          win.document.close();
          status.textContent = "Opened in a new tab.";
        });
      </script>
    </body>
    </html>
    

    try this code.

    Thanks.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.