Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 162e02396fa26f8dc844bb5d5df12cefabdceca4
https://github.com/WebKit/WebKit/commit/162e02396fa26f8dc844bb5d5df12cefabdceca4
Author: Elijah Sawyers <[email protected]>
Date: 2026-09-02 (Wed, 02 Sep 2026)
Changed paths:
M Source/WebCore/Headers.cmake
M Source/WebCore/WebCore.xcodeproj/project.pbxproj
A Source/WebCore/contentextensions/ContentRuleListBlockedLoadInfo.h
M Source/WebCore/loader/ResourceLoader.cpp
M Source/WebCore/loader/cache/CachedResourceLoader.cpp
M Source/WebCore/page/ChromeClient.h
A
Source/WebKit/Shared/Extensions/WebExtensionContentRuleListBlockedLoadInfo.h
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionControllerCocoa.mm
M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
M Source/WebKit/UIProcess/Extensions/WebExtensionController.h
M Source/WebKit/UIProcess/WebPageProxy.cpp
M Source/WebKit/UIProcess/WebPageProxy.h
M Source/WebKit/UIProcess/WebPageProxy.messages.in
M Source/WebKit/WebKit.xcodeproj/project.pbxproj
M
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIWebRequestCocoa.mm
M Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.h
M Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.messages.in
M Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
M Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIWebRequest.mm
Log Message:
-----------
Fire webRequest events for declarativeNetRequest-blocked loads
https://bugs.webkit.org/show_bug.cgi?id=313971
rdar://176177851
Reviewed by Timothy Hatcher.
This patch makes a Safari Web Extension fire webRequest.onBeforeRequest
followed by
webRequest.onErrorOccurred when a load is blocked by the extension's own
declarativeNetRequest rule,
matching Chrome and Firefox. Previously no webRequest event fired for such a
load.
dNR block rules are compiled to a content rule list and enforced by the
content-extension engine in
the WebProcess, before the load reaches the NetworkProcess where webRequest
events are generated, so
a blocked load never produced any webRequest event.
This patch adds a contentRuleListDidBlockLoad hook, fired at the
content-blocker enforcement sites,
which forwards the info to the UIProcess. From there, it is routed to the
extension whose own rule
list blocked the load. That extension's uses the existing webRequest dispatch
to fire onBeforeRequest
and then onErrorOccurred. The events are observe-only, dNR still blocks the
load.
The webRequest onErrorOccurred handler previously reported a hardcoded
"net::ERR_ABORTED" string. It
now reports the error's real localized description, so a blocked load reports
"The URL was blocked
by a content blocker" and no net:: error strings remain.
It's worth noting the extension that I used locally to test this:
https://jeurissen.co/webext-demos/webrequest-for-dnr-blocked
This extension registers the webRequest event observers and then immediately
creates a tab for a dNR-
blocked webpage with browser.tabs.create, which for some reason is not firing
the expected events.
Reloading the blocked webpages or navigating to them from the address bar does
fire the events. This
bug/behavior is not related to my change and occurs for any webRequest, even if
the webpage is not
blocked by dNR. I have filed rdar://186381292 to look into this.
Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIWebRequest.mm
* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/contentextensions/ContentRuleListBlockedLoadInfo.h: Added.
* Source/WebCore/loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestInternal):
* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::blockingContentRuleListIdentifiers):
(WebCore::CachedResourceLoader::requestResource):
* Source/WebCore/page/ChromeClient.h:
(WebCore::ChromeClient::contentRuleListDidBlockLoad):
* Source/WebKit/Shared/Extensions/WebExtensionContentRuleListBlockedLoadInfo.h:
Added.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::resourceLoadWasBlockedByDeclarativeNetRequest):
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionControllerCocoa.mm:
(WebKit::WebExtensionController::resourceLoadWasBlockedByContentRuleList):
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Source/WebKit/UIProcess/Extensions/WebExtensionController.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::contentRuleListDidBlockLoad):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.messages.in:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
*
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIWebRequestCocoa.mm:
(WebKit::WebExtensionContextProxy::resourceLoadDidBlockBeforeRequest):
(WebKit::WebExtensionContextProxy::resourceLoadDidCompleteWithError):
* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.h:
* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.messages.in:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::toResourceLoadInfoType):
(WebKit::parentFrameIDForBlockedLoad):
(WebKit::WebChromeClient::contentRuleListDidBlockLoad):
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIWebRequest.mm:
(TestWebKitAPI::TEST(WKWebExtensionAPIWebRequest,
WebRequestFiresForDeclarativeNetRequestBlockedLoad)):
Canonical link: https://commits.webkit.org/320336@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications