Skip to content

inspector: initial support for Network.loadNetworkResource #58077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 10, 2025

Conversation

islandryu
Copy link
Member

@islandryu islandryu commented Apr 29, 2025

Fixes: #57873

Adds initial support for Network.loadNetworkResource in the inspector.
https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-loadNetworkResource

how to load network resource

Resource fetching is done via a spawned child process to keep the inspector's event loop clean and isolated.
The JavaScript code for the fetch process is currently hardcoded, which may not be ideal, but I couldn't come up with a better approach at this point.

When --experimental-inspector-network-resource is set, a dedicated worker for loadNetworkResource is launched.
This worker fetches the resource and returns the result to the frontend.
https://github.com/nodejs/node/pull/58077/files#diff-5d3d58cbcfda008f49966a11d73863e67b78a237aa386f1fbdc5c9124136c1eb

check the behavior in chromium

To verify this change in Chromium, modify the section in the link as shown below and launch Chromium with the built DevTools frontend.

https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/Target.ts;l=87-88

      case Type.NODE:
        this.#capabilitiesMask = Capability.JS | Capability.NETWORK | Capability.TARGET | Capability.IO;
# open Chromium with built devtools-frontend
Chromium --custom-devtools-frontend=(file path)

other infomation

If this change is considered acceptable, I will send a follow-up change request to expand the Node.js DevTools target with IO support.
If it is necessary to wait until Network.loadNetworkResource becomes stable in CRDP, please feel free to keep this PR pending.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 29, 2025
@islandryu islandryu force-pushed the feat/inspector-load-resource branch from 86ba453 to 435c33f Compare April 29, 2025 13:02
@islandryu islandryu changed the title feat(inspector): initial support for Network.loadNetworkResource inspector: initial support for Network.loadNetworkResource Apr 29, 2025
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 91.92547% with 13 lines in your changes missing coverage. Please review.

Project coverage is 90.06%. Comparing base (0992d28) to head (04d8eca).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/inspector/network_resources.js 77.77% 6 Missing ⚠️
src/inspector/network_agent.cc 85.18% 2 Missing and 2 partials ⚠️
src/inspector_js_api.cc 72.72% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58077      +/-   ##
==========================================
- Coverage   90.06%   90.06%   -0.01%     
==========================================
  Files         641      645       +4     
  Lines      188846   188996     +150     
  Branches    37049    37063      +14     
==========================================
+ Hits       170087   170211     +124     
- Misses      11476    11488      +12     
- Partials     7283     7297      +14     
Files with missing lines Coverage Δ
lib/inspector.js 97.04% <100.00%> (+0.10%) ⬆️
src/inspector/io_agent.cc 100.00% <100.00%> (ø)
src/inspector/io_agent.h 100.00% <100.00%> (ø)
src/inspector/network_agent.h 100.00% <ø> (ø)
src/inspector/network_inspector.cc 90.90% <100.00%> (+0.90%) ⬆️
src/inspector/network_inspector.h 100.00% <ø> (ø)
src/inspector/network_resource_manager.cc 100.00% <100.00%> (ø)
src/inspector/worker_inspector.cc 95.89% <100.00%> (+0.05%) ⬆️
src/inspector/worker_inspector.h 100.00% <100.00%> (ø)
src/inspector_agent.cc 79.91% <100.00%> (+0.33%) ⬆️
... and 6 more

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@islandryu islandryu force-pushed the feat/inspector-load-resource branch 2 times, most recently from 5e20033 to 1f0c547 Compare May 27, 2025 12:43
@islandryu
Copy link
Member Author

@legendecas cc: @joyeecheung
I made changes to spawn a worker process for fetching.
It’s also possible to change it so that this behavior is delegated to the user via the Inspector JS API.
However, since the worker needs to be launched before the entry file is loaded in order to resolve source maps for Chrome DevTools, this part likely cannot be delegated to the user.

@islandryu islandryu force-pushed the feat/inspector-load-resource branch 2 times, most recently from 8b582eb to ce745ca Compare June 22, 2025 13:15
@islandryu
Copy link
Member Author

The implementation approach was significantly changed in commit ce745ca.
I talked with @legendecas, and we decided to adopt an implementation that only returns resources that were preemptively put, as it requires less consideration in terms of security and implementation complexity.

@islandryu islandryu requested a review from legendecas June 22, 2025 14:49
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thanks for the work! The new approach looks more straightforward as a first step to me.

@islandryu islandryu force-pushed the feat/inspector-load-resource branch 2 times, most recently from 0e70772 to 688e313 Compare June 29, 2025 15:41
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thank you! Some minor suggestions..

@legendecas legendecas added request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jul 3, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 3, 2025
@nodejs-github-bot
Copy link
Collaborator

@islandryu islandryu force-pushed the feat/inspector-load-resource branch from 2a37101 to 160eedb Compare July 3, 2025 12:58
@nodejs-github-bot
Copy link
Collaborator

@islandryu islandryu added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 4, 2025
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - inspector: initial support for Network.loadNetworkResource
   ⚠  - format
   ⚠  - fix build error
   ⚠  - fix unusual chars
   ⚠  - remove unix.h
   ⚠  - fix namespace
   ⚠  - fix lint
   ⚠  - fetch network resource on worker thread
   ⚠  - format
   ⚠  - format
   ⚠  - fix build error
   ⚠  - put method api
   ⚠  - remove comment
   ⚠  - avoid making networkResourceManager a static class.
   ⚠  - format
   ⚠  - add mutex lock to NetworkResourceManager
   ⚠  - Update src/inspector/network_agent.cc
   ⚠  - use url as stream id
   ⚠  - fix test
   ⚠  - fix lint
   ⚠  - use std::optional
   ⚠  - add flag to manpage
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/16067992462

@nodejs-github-bot
Copy link
Collaborator

@legendecas legendecas added inspector Issues and PRs related to the V8 inspector protocol and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Jul 7, 2025
@islandryu islandryu force-pushed the feat/inspector-load-resource branch from 2688004 to 04d8eca Compare July 9, 2025 05:38
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@islandryu islandryu requested a review from legendecas July 10, 2025 09:47
@legendecas legendecas added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 10, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 10, 2025
@nodejs-github-bot nodejs-github-bot merged commit b7db89f into nodejs:main Jul 10, 2025
56 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in b7db89f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. inspector Issues and PRs related to the V8 inspector protocol lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Network (CDP) to support external sourcemaps
5 participants