Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An empty or null PDF download URL usually means a value failed somewhere in the pipeline—not that the PDF format itself is broken. The request URL may be missing, fetch() may have returned an HTTP error or an unreadable opaque response, the response may not have been converted to a Blob, or the link may be assigned before an asynchronous operation finishes. Trace the values in that order: endpoint, response, body, Blob, object URL, and finally the anchor.

Find the stage that becomes empty

Start by logging the endpoint variable before making the request and the link’s href immediately before the user clicks it:

console.log('endpoint:', endpoint);
const response = await fetch(endpoint);
console.log('status:', response.status, 'ok:', response.ok, 'final URL:', response.url);
// ...after creating the URL...
console.log('href:', link.href);

If endpoint is already null, inspect the application state, route parameter, form value, or API response that should supply it. If the endpoint is valid but href is empty, inspect the awaited promise, exception handler, and the code that assigns the link. A common mistake is returning from an asynchronous function before the Blob URL has been created.

Do not treat a fulfilled fetch() promise as proof of success. Fetch normally fulfills with a Response even for statuses such as 404 or 500. Check response.ok (or the numeric status) before reading the body.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Use the correct bytes-to-link flow

When your endpoint returns PDF bytes to browser JavaScript, the reliable sequence is:

  1. Call fetch() with a real endpoint.
  2. Reject non-success HTTP statuses.
  3. Confirm that the response is the expected kind of content.
  4. Read the body with response.blob().
  5. Verify that the Blob is not empty.
  6. Create a temporary URL with URL.createObjectURL(blob).
  7. Assign that string to the anchor’s href before the click.

A Blob contains bytes and metadata; it is not itself a URL. URL.createObjectURL() is the step that produces a browser-local blob: address.

Complete browser example

async function preparePdfDownload(endpoint, link) {
  if (!endpoint) {
    throw new Error('No PDF endpoint was supplied');
  }

  const response = await fetch(endpoint, {
    credentials: 'include' // keep only if your endpoint uses browser cookies
  });

  if (!response.ok) {
    throw new Error(`PDF request failed: ${response.status} ${response.statusText}`);
  }

  const contentType = response.headers.get('content-type');
  if (!contentType || !contentType.toLowerCase().includes('application/pdf')) {
    throw new TypeError(`Expected application/pdf, got ${contentType || 'no content type'}`);
  }

  const blob = await response.blob();
  if (blob.size === 0) {
    throw new Error('PDF response body is empty');
  }

  const objectUrl = URL.createObjectURL(blob);
  link.href = objectUrl;
  link.download = 'document.pdf';

  // Revoke objectUrl after the download has been initiated and the browser
  // no longer needs it. Do not revoke it before the click consumes it.
  link.addEventListener('click', () => {
    setTimeout(() => URL.revokeObjectURL(objectUrl), 1000);
  }, { once: true });
}

Call it from a user action and handle errors visibly:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
downloadButton.addEventListener('click', async () => {
  downloadButton.disabled = true;
  try {
    await preparePdfDownload('/api/invoices/42/pdf', pdfLink);
    pdfLink.click();
  } catch (error) {
    console.error(error);
    status.textContent = error.message;
  } finally {
    downloadButton.disabled = false;
  }
});

The content-type and zero-size checks are practical safeguards. A server can return an HTML login page or JSON error with a successful transport, so also inspect the actual response when the file still does not open. A content type alone cannot prove that the bytes are a valid PDF.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Opaque responses and CORS: why the body appears to be null

An opaque response is what the browser exposes when a cross-origin request is made without readable CORS permission, commonly after using mode: "no-cors". It has status 0, no exposed headers, and a null body. Calling blob() on it produces a zero-size Blob with an empty type, which cannot provide a useful PDF download.

Do not use no-cors as a workaround. Configure the PDF server to return an appropriate Access-Control-Allow-Origin value for the requesting origin (and any credentials headers required by your authentication model), then make a normal request. If you cannot change the remote server, fetch the file through your own authenticated backend instead of trying to read it directly in the browser.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

What to inspect in DevTools

  • Request URL: confirm that it is the intended endpoint, not an undefined route or a page URL.
  • Status: investigate 3xx redirects, 401/403 authentication failures, 404 routes, and 5xx server errors.
  • Final URL: response.url reports the URL after redirects and can reveal a login page or a different host.
  • Response headers: check Content-Type and, for direct downloads, Content-Disposition.
  • Preview or response body: look for an HTML error page, JSON error object, or empty body instead of PDF bytes.

Choose between a direct URL and a Blob URL

Flow Use it when Checks and trade-offs
Direct server URL Your server returns a stable, downloadable address. Verify redirects, origin, authentication, media type, and disposition headers. The server can provide a suggested filename. The browser controls whether the file is saved or opened.
Fetched bytes plus Blob URL The PDF is protected, must be inspected, or must be transformed before the user receives it. Requires readable CORS or a same-origin request. The complete response is read into browser memory before the Blob URL is created. Revoke the object URL after use.

For a direct link, do not manufacture a blob: URL unless you have actually fetched bytes. Use the URL returned by your API, and inspect the final response when redirects are involved.

Why the anchor still does not download

The download attribute has limits

The anchor’s download attribute applies to same-origin URLs and to blob: or data: URLs. It does not force a cross-origin URL to download. Browser settings and server headers can also cause the document to open in a tab instead of being saved.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Server headers can override expectations

Content-Disposition influences whether a response is treated as an attachment and can supply a suggested filename. The response media type also affects handling. Check both headers on the final response, especially after redirects.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Click timing and cleanup

Assign href before calling click(). Do not revoke the object URL immediately after assigning it; revoke it only after the browser has had an opportunity to consume the download. If a framework re-renders the anchor, verify that it did not replace your assigned attribute.

Common failure patterns and fixes

Symptom Likely cause Fix
endpoint logs as null or undefined Missing state, route parameter, or API field. Validate the input before fetch(); trace the code that populates it and handle an absent value explicitly.
Fetch resolves with 404 or 500 HTTP errors do not automatically reject fetch(). Check response.ok and stop before creating a Blob.
Status is 0, headers are empty, Blob size is 0 Opaque cross-origin response. Remove no-cors; configure CORS or proxy the request through your server.
Blob URL exists but file is an HTML page Authentication redirect, login page, proxy error, or wrong endpoint. Inspect response.url, content type, and response bytes; send the required credentials.
Link opens but does not save Cross-origin URL, browser policy, or disposition/header behavior. Use a same-origin or Blob URL for download, and inspect Content-Disposition.
Download works intermittently Race between asynchronous fetch and click, or premature URL revocation. await every step, disable the button while loading, and revoke only after the click.

Performance, authentication, and reliability considerations

  • Large PDFs: Blob creation reads the complete response, so memory use rises with document size. A direct server download can avoid duplicating those bytes in the page.
  • Protected files: Decide whether cookies, an authorization header, or a backend proxy should supply credentials. Never expose a long-lived private token in a public link.
  • Retries: Retry only transient network or server failures, not a deterministic 401, 403, or 404. Show the status to the user and log a request identifier if your server provides one.
  • Validation: Treat an unexpected content type or empty body as an application error, not as a valid download.
  • Object URL lifecycle: Keep the URL alive through the click or open operation, then revoke it to release browser resources.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your actual need is to create a PDF of a web page rather than debug an application’s existing PDF endpoint, ScreenshotNeo provides a single request that returns a PDF. Its cleanup step accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI clients such as Claude and Cursor.

Use the documented API parameters and authentication shown in the ScreenshotNeo documentation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.pdf
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.pdf", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://stripe.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo failed: ${res.status}`);
const bytes = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.pdf', bytes));

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Create a free ScreenshotNeo account to try it.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Short diagnostic checklist

  1. Log the original endpoint and reject a missing value.
  2. Inspect status, response.ok, and response.url.
  3. Confirm CORS is readable; never rely on no-cors for PDF bytes.
  4. Verify the content type and nonzero body.
  5. Await response.blob(), then call URL.createObjectURL().
  6. Assign href before clicking and revoke the URL afterward.
  7. For direct links, inspect origin, redirects, Content-Disposition, and browser download behavior.

Frequently Asked Questions

Can I turn a PDF Blob directly into a download URL?

No. A Blob holds the response bytes. Call URL.createObjectURL(blob) to obtain a temporary blob: URL, then assign that string to the link.

Should I use data URLs instead of Blob URLs?

A data URL can work for small payloads, but it encodes the entire file into the URL. Blob URLs are the usual choice for fetched PDF responses and still require eventual revocation.

What information is needed to diagnose one specific null URL?

Provide the code that supplies the endpoint and assigns href, the request status and final URL, response headers, and whether the response is opaque. Those details identify which pipeline stage failed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.