URLPattern is a new web API that provides native support for matching URLs given a pattern string. It is designed to be usable both in javascript directly and by passing patterns to other web platform APIs; e.g. as a service worker scope.
This API has minimal interop and compat risk. It can easily be feature detected and a polyfill is available at: https://www.npmjs.com/package/urlpattern-polyfill
The URLPattern API will often be used with the URL API. To make this more natural we have tried to match URL behavior and API shape wherever possible. URLPattern is also similar in nature to RegExp and we have attempted to match its API shape as well; e.g. providing `test()` and `exec()` methods. In regard to the ergonomics of the pattern syntax itself, we have adopted the syntax from the popular javascript library path-to-regexp. Our hope is that using a popular syntax will result in the web API being more natural for developers to use.
The URLPattern API is easily feature detected and a polyfill is available at: https://www.npmjs.com/package/urlpattern-polyfill
The main security risks involve the addition of a new parser in the platform. Since parsers are common attack vectors it does represent a risk. We mitigate this risk by requiring that URLPattern strings must be parsed in the sandboxed renderer. In addition, we are actively fuzzing the parser.
Currently URLPattern does not have any special integration with devtools. The summary view of the URLPattern object is already useful for inspecting what patterns it will use to match. Exceptions are used to report errors in constructing a URLPattern. In the future it may be useful to provide some kind of syntax highlighting or checking of URLPattern syntax. This seems challenging, though, as the values are passed as plain javascript strings and are not a javascript type like regular expressions. This could be an area for future exploration, though.
On Thu, Jul 22, 2021 at 7:17 PM Ben Kelly <wande...@chromium.org> wrote:Gecko: No signal
WebKit: No signal
Web developers: No signalsI'd say applying the criteria defined in https://goo.gle/developer-signals it's safe to state developers are positive about this feature, based on the ReTweets, Likes, and linked blog posts on tweets matching the search query: https://twitter.com/search?q=url%3AURLPattern&src=typed_query&f=live. Specifically standing out: https://h3manth.com/new/blog/2021/urlpattern-api/ and https://twitter.com/wanderview/status/1339609333353615364. The article https://web.dev/urlpattern/ has just landed, but it's getting shared already.