Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright UrlMatch

From Leeroopedia
Revision as of 11:38, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Playwright_UrlMatch.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Implementation Page

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 functions
  • constructURLBasedOnBaseURL -- 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 either a or b

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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment