"excludeMatches" array in scripting.registerContentScripts() API is totally ignored in Safari web extensions

In a project to create a web extension for Safari, using scripting.registerContentScript() API to inject a bunch of scripts into web pages, I needed to manage a dynamic whitelist (i.e., web pages where the scripts should not be injected).

Fortunately, scripting.registerContentScripts() gives you the option of defining a list of web pages to be considered as a whitelist, using the excludeMatches parameter in the directive, to represent an array of pages where the script should not be injected.

Here just a sample of what I mean:

const matches = ['*://*/*'];
const excludeMatches = ['*://*.example.com/*'];

const directive = {
  id: 'injected-jstest',
  js: ['injectedscript.js'],
  matches: matches,
  excludeMatches: excludeMatches,
  persistAcrossSessions: false,
  runAt: 'document_start'
};
await browser.scripting.registerContentScripts([directive])
.catch(reason => { console.log("[SW] >>> inject script error:",reason); });

Of course, the whitelist (the excludeMatches array) is not static, but varies over time according to the needs of the moment.

Everything works perfectly in Chromium browsers (Chrome, Edge, ...) and Firefox, but fails miserably in Safari. In fact, Safari seems to completely ignore the excludeMatches parameter and injects the script even where it should not.

Has anyone had the same problem and solved it somehow?

NOTE : To test the correctness and capabilities of the API in each browser, I created a simple repository on Github with the extension code for Chromium, Firefox and Safari (XCode project).

For this issue I filed a bug report on Feedback Assistant: FB16590857

"excludeMatches" array in scripting.registerContentScripts() API is totally ignored in Safari web extensions
 
 
Q