Safari 16.4 extension - declarativeNetRequest: worker unable to load ruleset with requestDomains condition in rule

Safari extension MV3, MacBook Pro with Ventura 13.3.1, Safari 16.4 and Xcode 14.3

Although the “webkit features in Safari 16.4” claims to support requestDomains condition, any attempt to load a ruleset containing that condition fails.

The extension’s manifest declares the permissions and the ruleset to use:

"permissions": [ "declarativeNetRequestWithHostAccess", "declarativeNetRequestFeedback" ],

"declarative_net_request": { "rule_resources": [ { "id": "ADS", "enabled": false, "path": "rules/adstest.json" } ] }

This is the ruleset used for tests:

[ { "id": 1, "priority": 1, "action": { "type": "block" }, "condition": { "requestDomains": ["testpages.kzar.co.uk"] } } ]

The ruleset is enabled by the service worker with this function:

function EnableDNRRules() {

return new Promise( (resolve, reject) => {
    browser.declarativeNetRequest.updateEnabledRulesets(
        { enableRulesetIds: [ 'ADS' ] }, () => {
            console.log("LAST ERROR",browser.runtime.lastError)
            resolve(true);
            console.log("dNR rules enabled");            
        });
    });

}

The result in last error is: “Failed to apply rules” and rule is not used at all.

If I enable the ruleset directly in manifest, and not using the function to load the ruleset, the rule is simply not applied (so not loaded at all).

In Chrome and Firefox the same code/ruleset works fine, but not in Safari 16.4, although the docs say it works.

Using different condition (e.g. urlFilter) works fine in Safari too.

The expected behavior is to have requestDomains working too, as per 16.4 documentation.

The requestDomains issue seems to be just the top of the iceberg...

I added here a couple of images describing what happens when the extension runs. The Test extension works perfectly in Chrome and Firefox (with small adjustements). In Safari instead it's simply... confusing. While testing the extension I used some other (more complex and bigger) rulesets to check what happens... my doubt is that Safari "remembers" in some way ALL the rulesets I used and gives back strange behaviours... or maybe I have serious problems in my Mac 16 inch 2019 Intel core i7 with Ventura 13.3.1, Safari 16.4, Xcode 14.3, even if I reinstalled everything yesterday, just to be sure.

Attachments: background.js (as txt), manifest.json, a ruleset

Safari 16.4 extension - declarativeNetRequest: worker unable to load ruleset with requestDomains condition in rule
 
 
Q