Skip to content

✨RUM-16635 Add wildcard host pattern matching to WebView event bridge#4703

Open
barboraplasovska wants to merge 7 commits into
mainfrom
bplasovska/RUM-15826/webview-wildcard-matching
Open

✨RUM-16635 Add wildcard host pattern matching to WebView event bridge#4703
barboraplasovska wants to merge 7 commits into
mainfrom
bplasovska/RUM-15826/webview-wildcard-matching

Conversation

@barboraplasovska
Copy link
Copy Markdown

@barboraplasovska barboraplasovska commented Jun 1, 2026

Motivation

Part of RUM-15826. iOS SDK counterpart DataDog/dd-sdk-ios#2963.

Changes

Adds a new optional getAllowedWebViewHostPatterns?() method to the DatadogEventBridge interface. When present, canUseEventBridge() uses wildcard pattern matching via plain string operations instead of the legacy exact + subdomain-suffix path.

Invalid patterns (more than one *) produce a display.error console warning so customers see an actionable signal. Old Browser SDK versions receiving wildcard entries from a new mobile SDK will silently ignore them (literal match fails) while plain host entries continue to bridge normally.

Test instructions

CI should pass.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Jun 1, 2026

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 63.64%
Overall Coverage: 76.68% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7a9cd64 | Docs | Datadog PR Page | Give us feedback!

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented Jun 1, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 171.78 KiB 172.11 KiB +339 B +0.19%
Rum Profiler 7.88 KiB 7.88 KiB 0 B 0.00%
Rum Recorder 21.21 KiB 21.21 KiB 0 B 0.00%
Logs 54.30 KiB 54.62 KiB +326 B +0.59%
Rum Slim 129.68 KiB 130.00 KiB +326 B +0.25%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@barboraplasovska barboraplasovska changed the title RUM-15826 Add wildcard host pattern matching to WebView event bridge ✨RUM-15826 Add wildcard host pattern matching to WebView event bridge Jun 1, 2026
@barboraplasovska
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@barboraplasovska barboraplasovska force-pushed the bplasovska/RUM-15826/webview-wildcard-matching branch from 3884f98 to 6a7e913 Compare June 4, 2026 11:37
@barboraplasovska barboraplasovska marked this pull request as ready for review June 4, 2026 11:37
@barboraplasovska barboraplasovska requested a review from a team as a code owner June 4, 2026 11:37
@barboraplasovska barboraplasovska changed the title ✨RUM-15826 Add wildcard host pattern matching to WebView event bridge RUM-16635 Add wildcard host pattern matching to WebView event bridge Jun 4, 2026
@barboraplasovska barboraplasovska force-pushed the bplasovska/RUM-15826/webview-wildcard-matching branch from 6a7e913 to 5f724c9 Compare June 4, 2026 13:01
Comment thread packages/browser-core/src/transport/eventBridge.ts
@barboraplasovska barboraplasovska changed the title RUM-16635 Add wildcard host pattern matching to WebView event bridge ✨RUM-16635 Add wildcard host pattern matching to WebView event bridge Jun 4, 2026
@barboraplasovska barboraplasovska requested a review from mormubis June 5, 2026 08:21
Comment thread packages/browser-core/src/transport/eventBridge.spec.ts
Co-authored-by: Adrian de la Rosa <adrian.delarosa@datadoghq.com>
bridge
.getAllowedWebViewHosts()
.some((allowedHost) => currentHost === allowedHost || currentHost.endsWith(`.${allowedHost}`))
bridge?.getAllowedWebViewHosts().some((entry) => {
Copy link
Copy Markdown
Contributor

@gogusarov gogusarov Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion

we currently have a couple of duplicating checks both inside some iterator and inside matchesWildcardPattern function. I suggest to combine them into one function and use early returns for readability

export function canUseEventBridge(currentHost = globalObject.location?.hostname): boolean {
    const bridge = getEventBridge()
    return bridge?.getAllowedWebViewHosts().some((entry) =>
  matchesHostEntry(currentHost, entry)) ?? false
}

export function matchesHostEntry(host: string, entry: string): boolean
  {
    if (!entry.includes('*')) {
      return host === entry || host.endsWith(`.${entry}`)
    }

    const parts = entry.split('*')
    if (parts.length !== 2) {
      display.error(`Invalid WebView host pattern "${entry}": only one
  wildcard (*) is supported.`)
      return false
    }

    const [prefix, suffix] = parts

    return host.length >= prefix.length + suffix.length &&
  host.startsWith(prefix) && host.endsWith(suffix)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants