diff --git a/extensions/browser/extension_function_dispatcher.cc b/extensions/browser/extension_function_dispatcher.cc index a15ee68417cf1..e75f254b08fa7 100644 --- a/extensions/browser/extension_function_dispatcher.cc +++ b/extensions/browser/extension_function_dispatcher.cc @@ -281,7 +281,13 @@ void ExtensionFunctionDispatcher::DispatchWithCallbackInternal( const GURL* render_frame_host_url = nullptr; if (render_frame_host) { - render_frame_host_url = &render_frame_host->GetLastCommittedURL(); + // For error documents, GetLastCommittedURL() is the cross-origin URL whose + // load *failed*, not the opaque error origin actually committed in this + // process. Do not use it for URL-gated permission checks. This mirrors the + // IsErrorPage()/IsErrorDocument() handling in script_injection_tracker.cc. + render_frame_host_url = render_frame_host->IsErrorDocument() + ? &GURL::EmptyGURL() + : &render_frame_host->GetLastCommittedURL(); DCHECK_EQ(render_process_id, render_frame_host->GetProcess()->GetDeprecatedID()); }