Bug 244475 - declarativeNetRequest in web extensions does not support regexSubstitution
Summary: declarativeNetRequest in web extensions does not support regexSubstitution
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Extensions (show other bugs)
Version: Safari Technology Preview
Hardware: Mac (Apple Silicon) Unspecified
: P2 Blocker
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-08-29 00:37 PDT by vsr4493
Modified: 2023-05-22 07:04 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vsr4493 2022-08-29 00:37:08 PDT
Was looking into usage for declarativeNetRequest permission to configure redirects.

Expected behaviour: We should be able to add a dynamic redirect rule with a regexFilter and a regexSubstitution for the action.

Current behaviour: we get an error message that reads "`redirect` is missing either a `url`, `extensionPath`, or `transform` key" implying that regex substitution is not supported.

Sample payload:

```
browser.declarativeNetRequest.updateDynamicRules({ addRules: [
  { 
    action: {redirect: {regexSubstitution: "https://www.somesite.com/\\1"}, type: "redirect"}, 
    condition: {regexFilter: ".*?://test/(.*?)", resourceTypes: ["main_frame"]}, 
    priority: 1, 
    id: 1,
  }
]})
```

Other notes:

- Looking at these i see regexSubstitution should be supported, but i'm unable to determine where this pre-emptive check is happening:
  https://github.com/WebKit/WebKit/blob/dd956d5e74249681ddf904e0bbe401f308b65e0f/Source/WebCore/contentextensions/ContentExtensionActions.cpp#L302
  https://github.com/WebKit/WebKit/blob/2414d35395c931a94b7b8cedf131a2ca17fd8566/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp#L3103
Comment 1 vsr4493 2022-08-29 00:37:58 PDT
Scope: Safari web extensions 
API: declarativeNetRequest
Issue: Unexpected behaviour / missing functionality when calling updateDynamicRules()
Comment 2 Radar WebKit Bug Importer 2022-09-05 00:38:16 PDT
<rdar://problem/99560504>
Comment 3 luke.selker 2023-04-18 14:12:01 PDT
Hi, just wondering if there has been any investigation into this issue now that there is more support being published for Declarative Net Request. I'm still seeing the issue in version 16.4
Comment 4 Timothy Hatcher 2023-04-20 10:54:13 PDT
This should wor in Safari Technology Preview. It has not shipped in Safari yet.
Comment 5 luke.selker 2023-04-25 05:22:40 PDT
Thanks Timothy! I was able to confirm this is working in Safari Technology Preview. Do you have details on when Safari Technology Preview Releases get merged into production?
Comment 6 vsr4493 2023-05-22 07:04:57 PDT
Closing this as I see this was included in Technology preview and will likely be out soon on Safari stable. Thanks!