Determining if a WebContents is for a file:// URL

2 views
Skip to first unread message

Tim Judkins

unread,
Nov 4, 2025, 8:04:41 PMNov 4
to navigat...@chromium.org, CrxCore
Hi folk,

I was looking into a bug someone reported around the extensions pageCapture.saveAsMHTML() API failing for them with file:// URLs loaded in Chrome. Looking at the underlying code I see it is special casing the file:// URL permission check, but to determine if the page is for a file:// URL it is basically doing:

web_contents.GetPrimaryMainFrame()->GetLastCommittedOrigin().scheme() == url::kFileScheme

From what I understand Origin.scheme() returns an empty string for opaque URLs and in general file:// URLs are opaque, so it seems like this is not a good way to check if the page is for a file:// URL. Is there a recommended better way to check this?

Also worth noting that I can't seem to reproduce the bug locally with an unpacked extension and we even have a test for this, so I'm not exactly sure what case the origin ends up opaque and where this is going wrong for the reporter.

Rakina Zata Amni

unread,
Nov 4, 2025, 8:43:40 PMNov 4
to Tim Judkins, navigat...@chromium.org, CrxCore
Does web_contents.GetPrimaryMainFrame()->GetLastCommittedURL() not return a URL with a file:// scheme in this case too?

--
You received this message because you are subscribed to the Google Groups "navigation-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to navigation-de...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/navigation-dev/CALC37VdO70%2BC2UNYm3JTwP2_iqcoHm3G8PXA7Gf2wJVAmAvETQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages