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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

islandryu
Copy link
Contributor

@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.

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 88.40580% with 16 lines in your changes missing coverage. Please review.

Project coverage is 90.17%. Comparing base (52d95f5) to head (d5c6690).
Report is 181 commits behind head on main.

Files with missing lines Patch % Lines
src/inspector/network_agent.cc 83.50% 9 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58077      +/-   ##
==========================================
- Coverage   90.26%   90.17%   -0.10%     
==========================================
  Files         630      631       +1     
  Lines      185933   186808     +875     
  Branches    36450    36672     +222     
==========================================
+ Hits       167829   168448     +619     
- Misses      10972    11141     +169     
- Partials     7132     7219      +87     
Files with missing lines Coverage Δ
src/inspector/io_agent.cc 100.00% <100.00%> (ø)
src/inspector/io_agent.h 100.00% <100.00%> (ø)
src/inspector/network_inspector.cc 90.32% <100.00%> (+0.32%) ⬆️
src/inspector/network_inspector.h 100.00% <ø> (ø)
src/inspector_agent.cc 79.38% <100.00%> (+0.11%) ⬆️
src/node_options.cc 85.38% <100.00%> (+0.01%) ⬆️
src/node_options.h 98.89% <100.00%> (+<0.01%) ⬆️
src/inspector/network_agent.cc 68.75% <83.50%> (+7.09%) ⬆️

... and 109 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.

Comment on lines 4 to 6
namespace node {
namespace inspector {
namespace protocol {
Copy link
Member

Choose a reason for hiding this comment

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

Nit... since we're finally up on c++20, we can start using the more condensed namespace node::inspector::protocol { syntax where appropriate.

})
)";

auto [r, response, err] = spawnFetchProcess(code, env_, in_url);
Copy link
Member

Choose a reason for hiding this comment

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

I am not a fan of spawning a Node.js process for each Network.loadNetworkResource request from devtools frontend. A devtool frontend may call this method multiple times simultaneously if there are several source maps and spawning a Node.js process for each of them seems superfluous and resource draining.

As an alternative, we could expose this as a hook to JS inspector API so that it will be properly covered by environment variables like HTTP_PROXY and the permission model. Additionally, this allows the JS API hook to filter which domain the process is allowed to send request to.

Comment on lines +237 to +238
std::string command =
env->exec_path() + " --eval \"" + code.data() + "\" -- " + url.data();
Copy link
Member

Choose a reason for hiding this comment

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

This command is not used.

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++. 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
4 participants