feat(mcp): support wildcard port in allowedOrigins and blockedOrigins #38944
+51
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add support for wildcard port syntax like
http://localhost:*in thenetwork.allowedOriginsandnetwork.blockedOriginsconfig options. This allows restricting browser requests to a specific protocol and hostname while accepting any port number.Fixes microsoft/playwright-mcp#1337
Changes
packages/playwright/src/mcp/browser/context.ts: UpdateoriginOrHostGlob()to detect wildcard port patterns and generate the correct glob patternpackages/playwright/src/mcp/config.d.ts: Document supported origin formats in JSDoctests/mcp/request-blocking.spec.ts: Add 4 tests for wildcard port functionalityProblem
Previously, patterns like
http://localhost:*would fail to parse as a valid URL, causing the code to fall through to legacy host-only mode and generate an invalid glob pattern like*://http://localhost:*/**which never matches anything.Solution
Detect wildcard port patterns with regex before attempting URL parsing:
http://localhost:**://http://localhost:*/**❌http://localhost:*/**✅https://example.com:**://https://example.com:*/**❌https://example.com:*/**✅http://localhost:8000http://localhost:8000/**localhost*://localhost/**Use Case
This is useful when you want to: