-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
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
nodejs-github-bot
merged 5 commits into
nodejs:main
from
islandryu:feat/inspector-load-resource
Jul 10, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d99bb25
inspector: initial support for Network.loadNetworkResource
islandryu fbdcdcc
avoid making networkResourceManager a static class.
islandryu e3b871c
use url as stream id
islandryu 34e9882
use std::optional
islandryu 04d8eca
add flag to manpage
islandryu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const { getOptionValue } = require('internal/options'); | ||
const { validateString } = require('internal/validators'); | ||
const { putNetworkResource } = internalBinding('inspector'); | ||
|
||
/** | ||
* Registers a resource for the inspector using the internal 'putNetworkResource' binding. | ||
* @param {string} url - The URL of the resource. | ||
* @param {string} data - The content of the resource to provide. | ||
*/ | ||
function put(url, data) { | ||
if (!getOptionValue('--experimental-inspector-network-resource')) { | ||
process.emitWarning( | ||
'The --experimental-inspector-network-resource option is not enabled. ' + | ||
'Please enable it to use the putNetworkResource function'); | ||
return; | ||
} | ||
validateString(url, 'url'); | ||
validateString(data, 'data'); | ||
|
||
putNetworkResource(url, data); | ||
} | ||
|
||
module.exports = { | ||
put, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "io_agent.h" | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <string> | ||
#include <string_view> | ||
#include "crdtp/dispatch.h" | ||
#include "inspector/network_resource_manager.h" | ||
|
||
namespace node::inspector::protocol { | ||
|
||
void IoAgent::Wire(UberDispatcher* dispatcher) { | ||
frontend_ = std::make_shared<IO::Frontend>(dispatcher->channel()); | ||
IO::Dispatcher::wire(dispatcher, this); | ||
} | ||
|
||
DispatchResponse IoAgent::read(const String& in_handle, | ||
std::optional<int> in_offset, | ||
std::optional<int> in_size, | ||
String* out_data, | ||
bool* out_eof) { | ||
std::string url = in_handle; | ||
std::string txt = network_resource_manager_->Get(url); | ||
std::string_view txt_view(txt); | ||
|
||
int offset = 0; | ||
bool offset_was_specified = false; | ||
if (in_offset.has_value()) { | ||
offset = *in_offset; | ||
offset_was_specified = true; | ||
} else if (offset_map_.find(url) != offset_map_.end()) { | ||
offset = offset_map_[url]; | ||
} | ||
int size = 1 << 20; | ||
if (in_size.has_value()) { | ||
size = *in_size; | ||
} | ||
if (static_cast<std::size_t>(offset) < txt_view.length()) { | ||
std::string_view out_view = txt_view.substr(offset, size); | ||
out_data->assign(out_view.data(), out_view.size()); | ||
*out_eof = false; | ||
if (!offset_was_specified) { | ||
offset_map_[url] = offset + size; | ||
} | ||
} else { | ||
*out_data = ""; | ||
*out_eof = true; | ||
} | ||
|
||
return DispatchResponse::Success(); | ||
} | ||
|
||
DispatchResponse IoAgent::close(const String& in_handle) { | ||
std::string url = in_handle; | ||
network_resource_manager_->Erase(url); | ||
return DispatchResponse::Success(); | ||
} | ||
} // namespace node::inspector::protocol |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef SRC_INSPECTOR_IO_AGENT_H_ | ||
#define SRC_INSPECTOR_IO_AGENT_H_ | ||
|
||
#include <memory> | ||
#include "inspector/network_resource_manager.h" | ||
#include "node/inspector/protocol/IO.h" | ||
|
||
namespace node::inspector::protocol { | ||
|
||
class IoAgent : public IO::Backend { | ||
public: | ||
explicit IoAgent( | ||
std::shared_ptr<NetworkResourceManager> network_resource_manager) | ||
: network_resource_manager_(std::move(network_resource_manager)) {} | ||
void Wire(UberDispatcher* dispatcher); | ||
DispatchResponse read(const String& in_handle, | ||
std::optional<int> in_offset, | ||
std::optional<int> in_size, | ||
String* out_data, | ||
bool* out_eof) override; | ||
DispatchResponse close(const String& in_handle) override; | ||
|
||
private: | ||
std::shared_ptr<IO::Frontend> frontend_; | ||
std::unordered_map<std::string, int> offset_map_ = | ||
{}; // Maps stream_id to offset | ||
std::shared_ptr<NetworkResourceManager> network_resource_manager_; | ||
}; | ||
} // namespace node::inspector::protocol | ||
#endif // SRC_INSPECTOR_IO_AGENT_H_ |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.