Implementation:Microsoft Playwright UrlMatch
Appearance
Overview
UrlMatch provides URL matching utilities including glob-to-regex conversion and URL pattern matching, used by Playwright's network interception and routing features.
Description
This module provides:
globToRegexPattern-- converts glob patterns to regex strings with support for*(single path segment),**(multi-segment), and brace groups{a,b}urlMatches-- matches URLs against string patterns, glob patterns, RegExp, or predicate functionsconstructURLBasedOnBaseURL-- resolves relative URLs against a base URL- URL normalization and comparison utilities
The glob pattern matching follows standard conventions:
*matches any characters except/**matches any characters including/{a,b}matches eitheraorb
Usage
Used by page.route(), context.route(), and page.waitForURL() for URL pattern matching.
Code Reference
Source Location
packages/playwright-core/src/utils/isomorphic/urlMatch.ts (271 lines)
Function Signatures
export function globToRegexPattern(glob: string): string;
export function urlMatches(baseURL: string | undefined, urlString: string, match: string | RegExp | ((url: URL) => boolean) | undefined): boolean;
export function constructURLBasedOnBaseURL(baseURL: string | undefined, givenURL: string): string;
Import
import { globToRegexPattern, urlMatches, constructURLBasedOnBaseURL } from '../utils/isomorphic/urlMatch';
I/O Contract
globToRegexPattern
- Input: glob pattern string (e.g.,
'**/api/**') - Output: regex pattern string (e.g.,
'^((.+/)|)api/(.*)$')
urlMatches
- Input: base URL, URL to test, match pattern (string/RegExp/function)
- Output: boolean indicating match
constructURLBasedOnBaseURL
- Input: optional base URL and relative/absolute URL
- Output: fully resolved URL string
Related Pages
- Microsoft_Playwright_NetworkUtils -- Network operations using URL matching
- Microsoft_Playwright_StringUtils -- String utilities
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment