You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot save/download PDF from ASAR file in PDF viewer #49475
I have created a simple ASAR file that contains a PDF to avoid having to bundle the app. Unfortunately, it is not possible to add ASAR files in Electron Fiddle.
Dug into this a bit and it's a result of Chrome's download scaffolding in the pdf viewer not being asar-aware, so it tries to download the file at the virtual location where it doesn't actually exist. I'll look a bit more but this may require a patch which might not be justifiable for this specific an issue.
I also tried to see if I can fix this little issue and I also didn't find a way to do it without a patch. I also think it might not be worth it, but here's the most minimal patch I could come up with in case anybody feels differently.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Felix Rieseberg <[email protected]>
Date: Thu, 22 Jan 2026 21:34:25 -0800
Subject: feat: allow embedders to override file URL loader factory for
downloads
The download manager uses a hardcoded FileURLLoaderFactory for file://
URL downloads. This prevents embedders like Electron from using custom
URL loader factories (e.g., ASAR-aware loaders) for file:// downloads.
This change calls RegisterNonNetworkSubresourceURLLoaderFactories in the
file:// download path, pre-populating the factory map with the default
FileURLLoaderFactory. This allows embedders to detect and replace it with
their own implementation while maintaining backward compatibility.
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 7bedb1b17a20aad1730c959c03576ca3ff810e76..c985c41bdd02fd8d5a815ccdafb198c55f26f25c 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -1450,14 +1450,22 @@ void DownloadManagerImpl::BeginResourceDownloadOnChecksComplete(
DCHECK(params->url().SchemeIsBlob());
pending_url_loader_factory = blob_url_loader_factory->Clone();
} else if (params->url().SchemeIsFile()) {
+ ContentBrowserClient::NonNetworkURLLoaderFactoryMap factories;
+ factories.emplace(url::kFileScheme, FileURLLoaderFactory::Create(
+ browser_context_->GetPath(),
+ browser_context_->GetSharedCorsOriginAccessList(),
+ base::TaskPriority::USER_VISIBLE));
+ if (rfh) {
+ GetContentClient()
+ ->browser()
+ ->RegisterNonNetworkSubresourceURLLoaderFactories(
+ params->render_process_host_id(),
+ params->render_frame_host_routing_id(), params->initiator(),
+ &factories);
+ }
pending_url_loader_factory =
std::make_unique<network::WrapperPendingSharedURLLoaderFactory>(
- FileURLLoaderFactory::Create(
- browser_context_->GetPath(),
- browser_context_->GetSharedCorsOriginAccessList(),
- // USER_VISIBLE because download should progress
- // even when there is high priority work to do.
- base::TaskPriority::USER_VISIBLE));
+ std::move(factories.extract(url::kFileScheme).mapped()));
} else if (rfh && params->url().SchemeIs(content::kChromeUIScheme)) {
pending_url_loader_factory =
std::make_unique<network::WrapperPendingSharedURLLoaderFactory>(
Reacted by Florian Reinhart, Noah Gregory and Fichtelcoder
Activity
nikwen commentedon Jan 21, 2026
Thanks for reporting this issue! It's somewhat dangerous for maintainers to run arbitrary ASAR files.
Would you be able to create a GitHub repository with https://www.electronforge.io that allows us to build the ASAR file ourselves?
Thank you!
nikwen commentedon Jan 21, 2026
As a workaround, you can save the file on disk and open it from there.
florianreinhart commentedon Jan 21, 2026
The data.asar was created using the asar command line tool and just contains this PDF: https://pdfobject.com/pdf/sample.pdf
You could recreate the data.asar file yourself with that PDF.
Do you still want to me to create another test repo?
2 remaining items
nikwen commentedon Jan 21, 2026
Thank you very much! :)
codebytere commentedon Jan 22, 2026
Dug into this a bit and it's a result of Chrome's download scaffolding in the pdf viewer not being asar-aware, so it tries to download the file at the virtual location where it doesn't actually exist. I'll look a bit more but this may require a patch which might not be justifiable for this specific an issue.
fix: allow downloading files from asar archives
felixrieseberg commentedon Jan 23, 2026
I also tried to see if I can fix this little issue and I also didn't find a way to do it without a patch. I also think it might not be worth it, but here's the most minimal patch I could come up with in case anybody feels differently.
Branch with test: https://github.com/electron/electron/compare/main...felixrieseberg:electron:felixr-pdf-save?expand=1
nikwen commentedon Jan 23, 2026
@dhanushshet14 Please do not post AI-generated comments and commits. The AI-generated code is completely wrong.
fix: allow downloading files inside asar archives
fix: allow downloading files inside asar archives
fix: allow downloading files inside asar archives
fix: allow downloading files inside asar archives (#52808)
fix: allow downloading files inside asar archives (#52826)
fix: allow downloading files inside asar archives (#52827)
fix: allow downloading files inside asar archives (#52828)