Refactor ChromeCdpSnapshotService: remove dead code, deduplicate, cache stateless helpers#372
Draft
Refactor ChromeCdpSnapshotService: remove dead code, deduplicate, cache stateless helpers#372
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Net -113 lines. Cleanup pass on
ChromeCdpSnapshotServiceaddressing accumulated dead code, duplication, and per-call object allocation.Dead code removal
computeVisibility,computeInteractivity,calculateVisibility,buildPaintOrderMap,buildStackingContextMapDeduplication
findByDfsto replace 4 identical DFS traversals infindElement:evalDouble/evalInt/evalString/evalBooleanfrom local function definitions in bothbuildBrowserStateandcomputeFullClientInfointo shared private methodsObject caching
HighlightManagerandClickableElementDetectorpromoted to fields — both are stateless wrt their construction args, no reason to allocate per callNaming / docs
calculateScalability→calculateScrollability(it computes scrollability)DomService→SnapshotService(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/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)/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)/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/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)/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)/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/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)/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)/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/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)/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/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)/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)/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/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)/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/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)/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/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)/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)/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/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)/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)/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.