Skip to content

Conversation

@ohah
Copy link
Owner

@ohah ohah commented Feb 1, 2026

Align React Native inspector CDP with web client structure

Purpose

Align the React Native inspector’s CDP message handling (console, network) with the web client’s folder structure and code shape so both codebases use the same patterns and naming.

Description

  • Folder structure (aligned with web packages/client/src/cdp/)

    • cdp/domain/protocol.ts: Event constants (e.g. Runtime.consoleAPICalled, Network.requestWillBeSent).
    • cdp/domain/base.ts: Shared send path (sendCDPEvent, setCDPEventSender, setCDPConnectionReady), analogous to web BaseDomain.send.
    • cdp/domain/runtime.ts: Console hook logic (enable/disable/isEnabled).
    • cdp/domain/network.ts: Network hook logic (XHR/fetch).
    • cdp/common/value-to-remote-object.ts: JS value → CDP RemoteObject (same role as web common/remoteObject).
  • Single send API

    • Console and network hooks use only setCDPEventSender and setCDPConnectionReady.
    • setConsoleCDPSender / setNetworkCDPSender removed.
    • cdp-message.ts re-exports from cdp/domain/base; connect() calls setCDPEventSender(sender) and setCDPConnectionReady() once.
  • Backward compatibility

    • console/ and network/ re-export from cdp/domain/runtime and cdp/domain/network.
    • valueToRemoteObject is exported from cdp/common/value-to-remote-object and re-exported from console/index.
  • Tests

    • Console-hook and network-hook tests updated to use setCDPEventSender / setCDPConnectionReady and imports from cdp/domain/runtime and cdp/domain/network.
    • Value-to-remote-object test updated to import from cdp/common/value-to-remote-object.
    • New tests: cdp-domain-base.test.ts (send path: null sender, not ready, missing server info, successful send, serialize failure) and cdp-domain-protocol.test.ts (Event constant values).

Test coverage includes: console-hook, network-hook, value-to-remote-object, cdp/domain/base, cdp/domain/protocol.

How to test

  • From repo root: bun run format, bun run lint, then
    bun test packages/react-native-inspector/src/__tests__
  • Confirm console and network hooks still send CDP events when connected (manual check in app if needed).

Copilot review (applied)

  • runtime.ts
    • installHooks: On Object.defineProperties failure, reset originalConsole and originalDescriptors so the next call does not see inconsistent state.
    • uninstallHooks: Only clear backup maps after successful Object.defineProperties restoration; on failure return false without clearing so retry can restore.
  • network.ts
    • hookXHR: On Object.defineProperty failure, clear originalXHR and originalXHRDescriptor so a retry does not use partially-hooked values.
    • uninstallHooks: Only set originalXHR/originalFetch (and descriptors) to null/undefined after both XHR and fetch restorations succeed; on exception keep backups.
    • __ChromeRemoteDevToolsHooked: Added comment that the flag is on the constructor after defineProperty succeeds.
  • sub-agent-console-network.mdc: Clarified that the Object API pattern is currently applied in RN Inspector only; web client may follow later.

Safari/WebKit console object expand (fix)

  • Treeoutline (bundled): In Safari/WebKit, clicking the console object row or arrow did not expand/collapse because hasSelection() was true (caret) and isInTriangle/toggleOnClick could be false. For expandable nodes, selection is no longer checked (so caret does not block toggle), and toggle is allowed on any row click. Applied in bundled Treeoutline.js so Inspector (which loads from bundled) gets the fix.

Web playground console object test (docs)

  • DevToolsPlayground: Test Console button now also logs an expandable object { count: 1, status: 'ok' } for testing row expand/collapse (e.g. Safari).
  • Documentation (en/ko examples): Test Console description and example code updated to include the object log.

Additional info

  • Pre-commit: run bun run format and bun run lint before committing.
  • Post-commit summary (not committed): commit-summary-refactor-inspector-rn-cdp.md.

…work hooks

- Add sub-agent-console-network for web/RN console and network hook guidance
- runtime.ts: install/restore console hooks via Object.defineProperties and getOwnPropertyDescriptor
- network.ts: install/restore XHR and fetch via Object.defineProperty; add DOM lib reference; fix open and this types
@ohah ohah added the refactor refactor label Feb 1, 2026
Copilot AI review requested due to automatic review settings February 1, 2026 04:46
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

📊 Test Coverage Report - React Native Inspector

Summary

Metric Coverage
Functions 94.97%
Lines 84.94%

File Coverage

Click to expand
File Functions Lines Uncovered Lines
happydom.ts 100.00% 100.00% N/A
packages/react-native-inspector/src/cdp-message-handler.ts 100.00% 100.00% N/A
packages/react-native-inspector/src/cdp/common/object-store.ts 100.00% 100.00% N/A
packages/react-native-inspector/src/cdp/domain/protocol.ts 100.00% 100.00% N/A
packages/react-native-inspector/src/cdp/domain/runtime.ts 100.00% 96.08% 137,139-142
packages/react-native-inspector/src/metro-config.cjs 100.00% 92.86% 33,35-36
packages/react-native-inspector/src/server-info.ts 100.00% 92.31% N/A
packages/react-native-inspector/src/cdp/common/get-object-properties.ts 100.00% 91.43% 31,39
packages/react-native-inspector/src/utils.ts 100.00% 90.91% 14-15
packages/react-native-inspector/src/cdp/common/value-to-remote-object.ts 100.00% 90.23% 53,56,66,69,73,76,81-82,84-85,102,196-197
packages/react-native-inspector/src/redux-devtools-extension.ts 82.35% 87.89% 109-110,120-121,123-124,126,131,146-147,158-165,168-179,189,191,196-200,498-501,554,558,560-562
packages/react-native-inspector/src/cdp/domain/base.ts 100.00% 80.43% 45,58-62,69-71
packages/react-native-inspector/src/device-id.ts 83.33% 73.08% 20,61,72-76,78-80,82-85
packages/react-native-inspector/src/cdp/domain/network.ts 76.92% 68.50% 21-22,37,67,100-114,125,236-239,254-258,261-264,267-292,296-305,308-317,326-327,331-333,336-337,360,370-373,388,390-391,420-421,423-429,435,470,475-485,513-519,523-529,536,554,581-591
packages/react-native-inspector/src/cdp-message.ts 100.00% 56.25% 28-33
packages/react-native-inspector/src/websocket-client.ts 76.92% 39.05% 37-93,96-100,140-141

Generated by test coverage script

ohah added 2 commits February 1, 2026 13:48
- Guard onopen with disconnectRequested so open does not set sendFn after disconnect
- In onclose: clear ws and sendFn first, then return early if disconnectRequested; otherwise schedule retry
@ohah ohah added the bug Something isn't working label Feb 1, 2026
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

📊 Test Results

✅ Test Status: PASSED

📸 Screenshots

Screenshots are available as artifacts. Download them here.

Artifact name: playwright-screenshots

Screenshot files
  1. test-client-rn-2.png (test-client-rn-2)
  2. test-client-web-1.png (test-client-web-1)
  3. test-client-web-2.png (test-client-web-2)
  4. test-client-rn-1.png (test-client-rn-1)

…all and restore

- Console: descriptor backup/restore via defineProperties; idempotent second enable
- Network: XMLHttpRequest and fetch replace/restore via defineProperty; idempotent second enable
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors console and network hooks in the React Native Inspector to use Object.defineProperty and Object.defineProperties APIs instead of direct assignment. It also adds sub-agent documentation to guide the same pattern for both web and React Native clients.

Changes:

  • Added sub-agent documentation (.cursor/agents/sub-agent-console-network.mdc) describing the Object API pattern for console and network hooks
  • Updated console hooks in runtime.ts to use Object.defineProperties for installation/restoration and save original property descriptors
  • Updated network hooks in network.ts to use Object.defineProperty for XMLHttpRequest and fetch, with descriptor backup and improved typing (XHR.open parameters, fetch this context)

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.

File Description
.cursor/agents/sub-agent-console-network.mdc Sub-agent documentation defining the Object API pattern for console and network hooks across all clients
packages/react-native-inspector/src/cdp/domain/runtime.ts Refactored console hooks to use Object.defineProperties with descriptor backup/restore
packages/react-native-inspector/src/cdp/domain/network.ts Refactored XMLHttpRequest and fetch hooks to use Object.defineProperty with descriptor backup/restore, added DOM type reference, fixed typing for XHR.open and fetch wrapper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ohah ohah added the test test label Feb 1, 2026
@ohah ohah self-assigned this Feb 1, 2026
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Integration Tests

1 tests   1 ✅  18s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 6dd10fb.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

📱 Maestro Android Test Results

PASSED

Maestro Android tests have completed. Check the workflow run for details.

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

📱 Maestro iOS Test Results

PASSED

Maestro iOS tests have completed. Check the workflow run for details.

ohah added 4 commits February 1, 2026 14:46
- runtime.ts: reset originalConsole/originalDescriptors on defineProperties
  failure; clear backups only after successful uninstall restoration
- network.ts: clear originalXHR/originalXHRDescriptor on defineProperty
  failure in hookXHR; clear backup refs only after both XHR and fetch
  restorations succeed in uninstallHooks; document __ChromeRemoteDevToolsHooked
- sub-agent-console-network.mdc: clarify Object API pattern is RN-only for now
- Treeoutline: skip hasSelection check for expandable nodes so caret does
  not block toggle; allow toggle on any row click when expandable
  (isInTriangle/toggleOnClick may fail in WebKit)
- Apply same logic in bundled Treeoutline.js (Inspector loads bundled)
- DevToolsPlayground testConsole: log object { count: 1, status: 'ok' }
  for testing console row expand/collapse (e.g. Safari/WebKit)
- en/ko examples: document object log in Test Console and example code
ChromeRemoteDevToolsInspector native pod removed; RN inspector is
JavaScript-only.
@ohah ohah merged commit 97c4e4d into main Feb 1, 2026
20 checks passed
@ohah ohah deleted the feat/inspector-console-network-object-api branch February 1, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactor refactor test test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants