Skip to content

✨ [DEBUG-6504] Run the Live Debugger without 'unsafe-eval' in the page CSP - #5226

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
watson/DEBUG-6504/remove-unsafe-eval
Nov 18, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
watson/DEBUG-6504/remove-unsafe-eval

Conversation

@watson

@watson watson commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The Live Debugger only worked on pages whose Content Security Policy allows 'unsafe-eval', because it compiled probe conditions, message templates and capture expressions with new Function. Many applications won't loosen their CSP to use a debugger. With this PR, the Live Debugger works without 'unsafe-eval'.

Jira: DEBUG-6504

Changes

Each expression AST is now compiled once into nested closures, so no code is generated at runtime. Evaluation keeps the same semantics and side-effect guards (getters, coercion, Map/Set access), and the shared expression test table still passes.

A few edge cases behave differently. Please check them:

  • this with no receiver now evaluates to undefined. It used to be the global object.
  • Context variables named str or acc, or named like a built-in such as Array or Map, no longer break expressions. Before, the generated helpers shadowed them.
  • ReferenceError messages are now the same in every browser (foo is not defined).
  • Top-level let, const and class declarations of classic (non-module) scripts can't be referenced anymore. They aren't properties of window, and only evaluated code can read them, so there's no way around this without 'unsafe-eval'. Globals declared with var or function, and properties of window, still work. Module-scoped and bundler-scoped variables never worked.

Other changes:

  • A new e2e test runs a condition, a template and a capture expression on a page whose CSP doesn't allow 'unsafe-eval'. It fails on main. It calls the instrumented function from a page task because Chromium skips the CSP eval check for code that page.evaluate() runs. That's why the existing debugger e2e tests passed despite the requirement.
  • The README no longer has a CSP section, and the acorn dev dependency that the generated-code tests used is gone.
  • The bundle is about 2.1 KB smaller raw and 0.5 KB smaller gzipped.

Benchmarks

Most evaluations are faster, and the first hit of a probe is 7–24 times faster because nothing has to be parsed or compiled. any, all and filter are slower than on main from roughly 20 items up. Each item costs about 35 ns instead of about 2.5 ns, because every AST node is a function call that V8 can't merge the way it optimizes generated code. Reading @it, @key and @value from named properties instead of looking them up by name (second commit) already brought that down from about 58 ns. Conditions only run on hits that pass sampling, and templates and capture expressions only run when a snapshot is taken.

Per evaluation main This PR
x > 5 749 ns 38 ns
user.name == "John" && len(items) >= 3 874 ns 292 ns
startsWith(s, "foo") && matches(s, "[0-9]+") 982 ns 380 ns
any(items, @it > 1e9), 10 items 765 ns 227 ns
any(items, @it > 1e9), 100 items 949 ns 3.6 µs
any(items, @it > 1e9), 1000 items 3.0 µs 34.7 µs
First hit: compile and evaluate once main This PR
x > 5 52 µs 7.1 µs
user.name == "John" && len(items) >= 3 142 µs 8.0 µs
startsWith(s, "foo") && matches(s, "[0-9]+") 83 µs 3.5 µs

How these were measured:

  • Node 22 (V8), all expressions in one process, median of 5 runs.
  • The context has 7 variables. The main numbers include its wrapper, which spreads the context into a cached Function per set of context keys.
  • The any predicate never matches, so it evaluates every item.
  • Each first-hit probe has a unique literal, so V8 can't reuse compiled source.

Test instructions

yarn test:unit --spec 'packages/browser-debugger/**/*.spec.ts'
yarn test:e2e --project chromium -g "unsafe-eval"

To see the old failure, run the e2e test against main with only test/e2e/scenario/debugger.scenario.ts from this branch.

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

Reviewed with sol-loop: 1 round with gpt-6.1-sol on both commits (52fe33a). Sol verdict: approved

Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.

…e CSP

The Live Debugger compiled probe conditions, message templates and
capture expressions with `new Function`. That only works if the page CSP
allows 'unsafe-eval', which many applications won't add.

Each expression AST is now compiled once into nested closures, so no
code is generated at runtime. Evaluation keeps the same semantics and
side-effect guards, and the shared expression test table still passes.

- Add an e2e test that runs a condition, a template and a capture
  expression on a page whose CSP doesn't allow 'unsafe-eval'. It calls
  the instrumented function from a page task, because Chromium skips the
  CSP eval check for code that page.evaluate() runs.
- Remove the CSP section from the README and the acorn dev dependency
  that the generated-code tests used.

Environment: Datadog workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@watson
watson requested review from a team as code owners November 3, 2026 09:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T09:54:09.726942Z 52fe33a New commits
🔒 Security Review ✅ Completed 2026-11-03T09:52:22.980955Z 52fe33a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 190.91 KiB 190.91 KiB 0 B 0.00% ✅
Rum 190.88 KiB 190.88 KiB 0 B 0.00% ✅
Rum Salesforce Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.04 KiB 32.04 KiB 0 B 0.00% ✅
Rum Recorder 32.04 KiB 32.04 KiB 0 B 0.00% ✅
Logs 59.82 KiB 59.82 KiB 0 B 0.00% ✅
Rum Slim 147.03 KiB 147.03 KiB 0 B 0.00% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 221.33 KiB 221.33 KiB 0 B 0.00% ✅
Rum Shopify Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 74.47%
• Overall Coverage: 77.15% (-0.17%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 52fe33a | Docs | View more details | Give us feedback!

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

Probe expressions referencing classic-script global let, const, or class bindings regress: the new resolver throws ReferenceError or incorrectly reports them as undefined. A focused reproduction confirmed that the base evaluator resolves these bindings successfully.

Open Bits AI session

🤖 Bits Code Review · Commit 4f7606c

`any`, `all` and `filter` looked up `@it`, `@key` and `@value` by name
on every item, through the same property access as every other
reference, so V8 couldn't optimize it. They're now read from named
properties of the iteration, which roughly halves the cost per item.

Also document that the top-level let, const and class declarations of
classic scripts can't be resolved without evaluated code.

Environment: Datadog workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52fe33a0db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@watson

watson commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-18 13:46:47 UTC ℹ️ Start processing command /merge


2026-11-18 13:46:51 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 20m (p90).


2026-11-18 14:05:37 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 38a918f into main Nov 18, 2026
38 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the watson/DEBUG-6504/remove-unsafe-eval branch November 18, 2026 14:05
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants