Regex for UserScripts rules?

131 views
Skip to first unread message

Jeff Johnson

unread,
Apr 6, 2024, 10:13:33 AM4/6/24
to Chromium Extensions
I've mostly migrated my MV2 extension to MV3, but there's one feature that I'm finding it impossible to migrate: the ability to inject user-defined HTML script elements into the web page. Looking at the new UserScripts API, the fundamental problem is that the URL matching rules seem very limited and don't fit with the URL matching algorithm of my own extension. Is there any way to get regex support? The "matches", "excludeMatches", "includeGlobs", and "excludeGlobs" keys seem quite primitive and arbitrarily limited.

My extension has always checked the URL at page load time and has a "best match" algorithm, which is a poor fit for UserScripts static rules. Even if I could use regex, which as far as I can tell isn't possible, I would have to add a bunch of "excludes" to every user script rule to handle possible overlaps of the user settings, which is awkward, overly complex, and possibly slow.

wOxxOm

unread,
Apr 6, 2024, 3:41:47 PM4/6/24
to Chromium Extensions, Jeff Johnson
There's no way and it's truly terrible for Tampermonkey/Violentmonkey with document_start scripts as they'll have to run it on all pages in a passive state and use RegExp checks before running it. The code will have to be transferred into the page for each such script, it will have to be pre-parsed in its entirety by V8 which may take a noticeable time, the RegExp will need to be compiled and executed. In each tab and iframe for each navigation.
Reply all
Reply to author
Forward
0 new messages