Skip to content

✨ Add @datadog/browser-native isolation layer for browser APIs#4245

Draft
mormubis wants to merge 20 commits intomainfrom
adlrb/browser-layer
Draft

✨ Add @datadog/browser-native isolation layer for browser APIs#4245
mormubis wants to merge 20 commits intomainfrom
adlrb/browser-layer

Conversation

@mormubis
Copy link
Contributor

Motivation

Create a clean isolation layer between SDK code and native browser APIs. The long-term goal is to scope BrowserStack unit tests exclusively to this package — all other packages can then run without real-browser testing since their browser API access goes through testable wrappers.

Changes

New package: @datadog/browser-native

Zero-dependency package at the base of the dependency graph (below @datadog/browser-core). Exposes native browser API callsites as standalone named functions, matching browser API names where applicable and using a getter/setter convention for property accesses.

Exports:

  • fetch / sendBeacon — network APIs (with Zone.js bypass for fetch)
  • addEventListener / removeEventListener — event APIs (with Zone.js bypass + EventTarget.prototype pattern)
  • getCookie / setCookiedocument.cookie accessor
  • getReadyStatedocument.readyState
  • getVisibilityStatedocument.visibilityState
  • nowperformance.now()

Migration: packages/core/src/browser/

Updated all direct native callsites in core/src/browser/ to import from @datadog/browser-native instead:

  • fetch.ts → re-exports fetch from @datadog/browser-native
  • cookie.ts → uses getCookie / setCookie
  • addEventListener.ts → uses addEventListener / removeEventListener (removes manual listenerTarget computation and getZoneJsOriginalValue calls)
  • runOnReadyState.ts → uses getReadyState
  • pageMayExitObservable.ts → uses getVisibilityState

Note: Planning artifacts (design doc, implementation plan) are in .planning/plans/. This code was largely AI agent generated.

Test instructions

yarn test:unit
yarn typecheck
yarn lint

All unit tests (3226), typecheck, and lint 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

claude and others added 19 commits February 19, 2026 16:56
- STACK.md - Technologies and dependencies
- ARCHITECTURE.md - System design and patterns
- STRUCTURE.md - Directory layout
- CONVENTIONS.md - Code style and patterns
- TESTING.md - Test structure
- INTEGRATIONS.md - External services
- CONCERNS.md - Technical debt and issues
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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


1 out of 2 committers have signed the CLA.
✅ (mormubis)[https://github.com/mormubis]
@claude
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Feb 26, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 171.96 KiB 172.63 KiB +686 B +0.39%
Rum Profiler 4.67 KiB 4.67 KiB -1 B -0.02%
Rum Recorder 24.88 KiB 24.88 KiB -1 B -0.00%
Logs 56.29 KiB 56.75 KiB +469 B +0.81%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 127.73 KiB 128.20 KiB +480 B +0.37%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
addglobalcontext N/A 0.0042 N/A
addaction N/A 0.013 N/A
adderror N/A 0.0127 N/A
addtiming N/A 0.003 N/A
startview N/A 0.0137 N/A
startstopsessionreplayrecording N/A 0.0007 N/A
logmessage N/A 0.0143 N/A
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
addglobalcontext N/A 26.42 KiB N/A
addaction N/A 115.80 KiB N/A
addtiming N/A 26.61 KiB N/A
adderror N/A 114.30 KiB N/A
startstopsessionreplayrecording N/A 25.61 KiB N/A
startview N/A 502.69 KiB N/A
logmessage N/A 44.98 KiB N/A

🔗 RealWorld

@datadog-datadog-prod-us1-2
Copy link

datadog-datadog-prod-us1-2 bot commented Feb 26, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 62.79%
Overall Coverage: 77.08% (-0.08%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 08b9c07 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

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.

2 participants