Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/api/inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session
Copy link
Member

Choose a reason for hiding this comment

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

Preferrably, an array of errors should be thrown as AggregateError.


This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -537,6 +538,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -551,6 +553,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -566,6 +569,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -581,6 +585,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -596,6 +601,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -610,6 +616,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -624,6 +631,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand All @@ -638,6 +646,7 @@ added:
-->

* `params` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the `--experimental-network-inspection` flag enabled.

Expand Down Expand Up @@ -696,6 +705,7 @@ added:
* `isLocalStorage` {boolean}
* `key` {string}
* `newValue` {string}
* Returns: {Array} An array of errors from each session

This feature is only available with the
`--experimental-storage-inspection` flag enabled.
Expand All @@ -716,6 +726,7 @@ added:
* `storageKey` {string}
* `isLocalStorage` {boolean}
* `key` {string}
* Returns: {Array} An array of errors from each session

This feature is only available with the
`--experimental-storage-inspection` flag enabled.
Expand All @@ -738,6 +749,7 @@ added:
* `key` {string}
* `oldValue` {string}
* `newValue` {string}
* Returns: {Array} An array of errors from each session

This feature is only available with the
`--experimental-storage-inspection` flag enabled.
Expand All @@ -757,6 +769,7 @@ added:
* `securityOrigin` {string}
* `storageKey` {string}
* `isLocalStorage` {boolean}
* Returns: {Array} An array of errors from each session

This feature is only available with the
`--experimental-storage-inspection` flag enabled.
Expand All @@ -775,6 +788,7 @@ added:
* `params` {Object}
* `isLocalStorage` {boolean}
* `storageMap` {Object}
* Returns: {Array} An array of errors from each session

This feature is only available with the
`--experimental-storage-inspection` flag enabled.
Expand Down
2 changes: 1 addition & 1 deletion lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function inspectorWaitForDebugger() {
function broadcastToFrontend(eventName, params = kEmptyObject) {
validateString(eventName, 'eventName');
validateObject(params, 'params');
emitProtocolEvent(eventName, params);
return emitProtocolEvent(eventName, params);
}

const Network = {
Expand Down
27 changes: 27 additions & 0 deletions src/inspector/dom_storage_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ using v8::Local;
using v8::Object;
using v8::Value;

static void ThrowEventError(v8::Isolate* isolate, const std::string& message) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, message.c_str()).ToLocalChecked()));
}

std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject(
Local<Context> context, Local<Object> storage_id_obj) {
protocol::String security_origin;
Isolate* isolate = Isolate::GetCurrent();
if (!ObjectGetProtocolString(context, storage_id_obj, "securityOrigin")
.To(&security_origin)) {
ThrowEventError(isolate, "Missing securityOrigin in storageId");
Copy link
Member

@legendecas legendecas Mar 9, 2026

Choose a reason for hiding this comment

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

IIUC, this would throw an identical error for each session connected. Can we validate the object shape once so that the error is only thrown once? This would also prevent returning an array of errors in the JS API.

return {};
}
bool is_local_storage =
ObjectGetBool(context, storage_id_obj, "isLocalStorage").FromMaybe(false);
protocol::String storageKey;
if (!ObjectGetProtocolString(context, storage_id_obj, "storageKey")
.To(&storageKey)) {
ThrowEventError(isolate, "Missing storageKey in storageId");
return {};
}

Expand Down Expand Up @@ -119,8 +127,10 @@ protocol::DispatchResponse DOMStorageAgent::clear(

void DOMStorageAgent::domStorageItemAdded(Local<Context> context,
Local<Object> params) {
Isolate* isolate = env_->isolate();
Local<Object> storage_id_obj;
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
ThrowEventError(isolate, "Missing storageId in event");
return;
}

Expand All @@ -132,19 +142,23 @@ void DOMStorageAgent::domStorageItemAdded(Local<Context> context,

protocol::String key;
if (!ObjectGetProtocolString(context, params, "key").To(&key)) {
ThrowEventError(isolate, "Missing key in event");
return;
}
protocol::String new_value;
if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) {
ThrowEventError(isolate, "Missing newValue in event");
return;
}
frontend_->domStorageItemAdded(std::move(storage_id), key, new_value);
}

void DOMStorageAgent::domStorageItemRemoved(Local<Context> context,
Local<Object> params) {
Isolate* isolate = env_->isolate();
Local<Object> storage_id_obj;
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
ThrowEventError(isolate, "Missing storageId in event");
return;
}
std::unique_ptr<protocol::DOMStorage::StorageId> storage_id =
Expand All @@ -156,15 +170,18 @@ void DOMStorageAgent::domStorageItemRemoved(Local<Context> context,

protocol::String key;
if (!ObjectGetProtocolString(context, params, "key").To(&key)) {
ThrowEventError(isolate, "Missing key in event");
return;
}
frontend_->domStorageItemRemoved(std::move(storage_id), key);
}

void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,
Local<Object> params) {
Isolate* isolate = env_->isolate();
Local<Object> storage_id_obj;
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
ThrowEventError(isolate, "Missing storageId in event");
return;
}

Expand All @@ -177,14 +194,17 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,

protocol::String key;
if (!ObjectGetProtocolString(context, params, "key").To(&key)) {
ThrowEventError(isolate, "Missing key in event");
return;
}
protocol::String old_value;
if (!ObjectGetProtocolString(context, params, "oldValue").To(&old_value)) {
ThrowEventError(isolate, "Missing oldValue in event");
return;
}
protocol::String new_value;
if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) {
ThrowEventError(isolate, "Missing newValue in event");
return;
}
frontend_->domStorageItemUpdated(
Expand All @@ -193,8 +213,10 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,

void DOMStorageAgent::domStorageItemsCleared(Local<Context> context,
Local<Object> params) {
Isolate* isolate = env_->isolate();
Local<Object> storage_id_obj;
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
ThrowEventError(isolate, "Missing storageId in event");
return;
}
std::unique_ptr<protocol::DOMStorage::StorageId> storage_id =
Expand All @@ -212,27 +234,32 @@ void DOMStorageAgent::registerStorage(Local<Context> context,
HandleScope handle_scope(isolate);
bool is_local_storage;
if (!ObjectGetBool(context, params, "isLocalStorage").To(&is_local_storage)) {
ThrowEventError(isolate, "Missing isLocalStorage in event");
return;
}
Local<Object> storage_map_obj;
if (!ObjectGetObject(context, params, "storageMap")
.ToLocal(&storage_map_obj)) {
ThrowEventError(isolate, "Missing storageMap in event");
return;
}
std::unordered_map<std::string, std::string>& storage_map =
is_local_storage ? local_storage_map_ : session_storage_map_;
Local<Array> property_names;
if (!storage_map_obj->GetOwnPropertyNames(context).ToLocal(&property_names)) {
ThrowEventError(isolate, "Failed to get property names from storageMap");
return;
}
uint32_t length = property_names->Length();
for (uint32_t i = 0; i < length; ++i) {
Local<Value> key_value;
if (!property_names->Get(context, i).ToLocal(&key_value)) {
ThrowEventError(isolate, "Failed to get key from storageMap");
return;
}
Local<Value> value_value;
if (!storage_map_obj->Get(context, key_value).ToLocal(&value_value)) {
ThrowEventError(isolate, "Failed to get value from storageMap");
return;
}
node::Utf8Value key_utf8(isolate, key_value);
Expand Down
Loading
Loading