Skip to content

inspector: auto collect webstorage data#62145

Open
islandryu wants to merge 1 commit intonodejs:mainfrom
islandryu:autoCollectWebStorage
Open

inspector: auto collect webstorage data#62145
islandryu wants to merge 1 commit intonodejs:mainfrom
islandryu:autoCollectWebStorage

Conversation

@islandryu
Copy link
Member

@islandryu islandryu commented Mar 7, 2026

Web Storage data collection, which previously required explicitly firing events to send data to DevTools, is now performed automatically within Node.js.
Web Storage will appear in DevTools simply by specifying --experimental-storage-inspection, without requiring any code changes.

This feature relies on the changes introduced in the following change request, so it can be verified with the latest DevTools commit:
https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7274801

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/inspector

@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 Mar 7, 2026
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 94.31818% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.64%. Comparing base (a6e9e32) to head (1e514ca).
⚠️ Report is 49 commits behind head on main.

Files with missing lines Patch % Lines
src/inspector/dom_storage_agent.cc 83.33% 1 Missing and 4 partials ⚠️
src/node_webstorage.cc 82.14% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62145      +/-   ##
==========================================
- Coverage   89.64%   89.64%   -0.01%     
==========================================
  Files         676      677       +1     
  Lines      206240   206713     +473     
  Branches    39514    39576      +62     
==========================================
+ Hits       184891   185306     +415     
- Misses      13465    13500      +35     
- Partials     7884     7907      +23     
Files with missing lines Coverage Δ
lib/internal/inspector/webstorage.js 100.00% <100.00%> (ø)
lib/internal/webstorage.js 100.00% <100.00%> (ø)
src/node_webstorage.h 83.33% <ø> (ø)
src/inspector/dom_storage_agent.cc 67.93% <83.33%> (+18.25%) ⬆️
src/node_webstorage.cc 75.24% <82.14%> (+0.49%) ⬆️

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

? std::make_unique<std::unordered_map<std::string, std::string>>(
local_storage_map_)
: std::make_unique<std::unordered_map<std::string, std::string>>(
session_storage_map_);
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to make a copy of the map here in the !storage_map.empty() case – you can keep using a const std::unordered_map<...>* pointer instead of a reference, along with an std::optional<std::unordered_map<...>> that is only filled when needed


std::optional<node::webstorage::Storage*> DOMStorageAgent::getWebStorage(
bool is_local_storage) {
std::string var_name = is_local_storage ? "localStorage" : "sessionStorage";
Copy link
Member

Choose a reason for hiding this comment

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

Using std::string_view is preferred when possible. In this case, you can take it a bit further and use FIXED_ONE_BYTE_STRING.

->Get(env_->context(),
v8::String::NewFromUtf8(env_->isolate(), var_name.c_str())
.ToLocalChecked())
.ToLocal(&web_storage_val) ||
Copy link
Member

Choose a reason for hiding this comment

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

This feels like an exception that should be caught?

return Array::New(env()->isolate(), values.data(), values.size());
}

std::unordered_map<std::string, std::string> Storage::GetAll() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::unordered_map<std::string, std::string> Storage::GetAll() {
std::unordered_map<std::string, std::string> Storage::GetAll() const {

?

std::string value;
for (size_t i = 0; i < value_size; ++i) {
value.push_back(static_cast<char>(value_uint16[i]));
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a very slow way to create strings, and completely broken for characters outside of the ISO-8859-1 range.

You'll want to look at the UTF-16-to-UTF-8 conversion functions exposed by simdutf and use those instead. (Alternatively, you could return std::u16string here, but that requires extra handling on the caller side then.)

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.

3 participants