Skip to content

Refactor ChromeCdpSnapshotService: remove dead code, deduplicate, cache stateless helpers#372

Draft
Copilot wants to merge 2 commits into4.6.xfrom
copilot/review-chrome-cdp-snapshot-service-again
Draft

Refactor ChromeCdpSnapshotService: remove dead code, deduplicate, cache stateless helpers#372
Copilot wants to merge 2 commits into4.6.xfrom
copilot/review-chrome-cdp-snapshot-service-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 8, 2026

Net -113 lines. Cleanup pass on ChromeCdpSnapshotService addressing accumulated dead code, duplication, and per-call object allocation.

Dead code removal

  • Removed 5 unused private methods: computeVisibility, computeInteractivity, calculateVisibility, buildPaintOrderMap, buildStackingContextMap
  • Removed commented-out paint order / stacking context map block

Deduplication

  • Extracted findByDfs to replace 4 identical DFS traversals in findElement:
    private fun findByDfs(root: DOMTreeNodeEx, predicate: (DOMTreeNodeEx) -> Boolean): DOMTreeNodeEx? {
        if (predicate(root)) return root
        root.children.forEach { child -> findByDfs(child, predicate)?.let { return it } }
        root.shadowRoots.forEach { shadow -> findByDfs(shadow, predicate)?.let { return it } }
        root.contentDocument?.let { doc -> findByDfs(doc, predicate)?.let { return it } }
        return null
    }
  • Lifted evalDouble/evalInt/evalString/evalBoolean from local function definitions in both buildBrowserState and computeFullClientInfo into shared private methods

Object caching

  • HighlightManager and ClickableElementDetector promoted to fields — both are stateless wrt their construction args, no reason to allocate per call

Naming / docs

  • calculateScalabilitycalculateScrollability (it computes scrollability)
  • KDoc: DomServiceSnapshotService (actual implemented interface)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • accounts.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5688 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.10 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,14262701824678284440,14102384351763258509,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
  • android.clients.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=6236 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.3 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,16768613678963846256,10608664309925382043,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
  • clients2.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5688 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.10 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,14262701824678284440,14102384351763258509,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
  • google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=6236 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.3 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,16768613678963846256,10608664309925382043,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
  • safebrowsingohttpgateway.googleapis.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5688 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.10 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,14262701824678284440,14102384351763258509,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
  • www.aliyun.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
  • www.baidu.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=6236 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.3 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,16768613678963846256,10608664309925382043,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
  • www.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5688 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.10 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,14262701824678284440,14102384351763258509,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
  • www.xiaohongshu.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=5521 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.1 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,17774685391240185287,12506439105555060972,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome-stable --headless --disable-gpu --hide-scrollbars --remote-debugging-port=0 --no-default-browser-check --no-first-run --no-startup-window --mute-audio --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-geolocation --disable-blink-features=AutomationControlled --metrics-recording-only (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --ignore-certificate-errors --use-angle=swiftshader-webgl --mute-audio --ignore-certificate-errors --crashpad-handler-pid=6236 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/browser4-REDACTED/context/groups/test/PULSAR_CHROME/cx.3 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,16768613678963846256,10608664309925382043,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…cache objects

- Fix KDoc: reference SnapshotService instead of DomService
- Remove unused methods: computeVisibility, computeInteractivity,
  calculateVisibility, buildPaintOrderMap, buildStackingContextMap
- Remove commented-out code for paint order/stacking context maps
- Rename calculateScalability to calculateScrollability
- Extract findByDfs helper to eliminate 4 duplicate DFS traversals
- Extract buildCssMatcher for CSS selector matching in findElement
- Cache HighlightManager and ClickableElementDetector as fields
- Extract shared evalDouble/evalInt/evalString/evalBoolean helpers
  from buildBrowserState and computeFullClientInfo

Co-authored-by: galaxyeye <1701451+galaxyeye@users.noreply.github.com>
Copilot AI changed the title [WIP] Review ChromeCdpSnapshotService for potential improvements Refactor ChromeCdpSnapshotService: remove dead code, deduplicate, cache stateless helpers Mar 8, 2026
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