Skip to content

Commit 931b766

Browse files
committed
use localStorage file as storageKey
1 parent 2df3321 commit 931b766

File tree

10 files changed

+39
-28
lines changed

10 files changed

+39
-28
lines changed

doc/api/cli.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,17 +1122,6 @@ added:
11221122
11231123
Enable experimental support for inspector network resources.
11241124

1125-
### `--experimental-inspector-storage-key=key`
1126-
1127-
<!-- YAML
1128-
added:
1129-
- REPLACEME
1130-
-->
1131-
1132-
> Stability: 1.1 - Active Development
1133-
1134-
Specify a inspector storage key used by the Node.js inspector when connecting to Chrome DevTools.
1135-
11361125
### `--experimental-loader=module`
11371126

11381127
<!-- YAML
@@ -1237,6 +1226,17 @@ added:
12371226

12381227
Use this flag to enable [ShadowRealm][] support.
12391228

1229+
### `--experimental-storage-inspection`
1230+
1231+
<!-- YAML
1232+
added:
1233+
- REPLACEME
1234+
-->
1235+
1236+
> Stability: 1.1 - Active Development
1237+
1238+
Enable experimental support for storage inspection
1239+
12401240
### `--experimental-test-coverage`
12411241

12421242
<!-- YAML

doc/api/inspector.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ added:
698698
* `newValue` {string}
699699

700700
This feature is only available with the
701-
`--experimental-inspector-storage-key=key` flag enabled.
701+
`--experimental-storage-inspection` flag enabled.
702702

703703
Broadcasts the `DOMStorage.domStorageItemAdded` event to connected frontends.
704704
This event indicates that a new item has been added to the storage.
@@ -718,7 +718,7 @@ added:
718718
* `key` {string}
719719

720720
This feature is only available with the
721-
`--experimental-inspector-storage-key=key` flag enabled.
721+
`--experimental-storage-inspection` flag enabled.
722722

723723
Broadcasts the `DOMStorage.domStorageItemRemoved` event to connected frontends.
724724
This event indicates that an item has been removed from the storage.
@@ -740,7 +740,7 @@ added:
740740
* `newValue` {string}
741741

742742
This feature is only available with the
743-
`--experimental-inspector-storage-key=key` flag enabled.
743+
`--experimental-storage-inspection` flag enabled.
744744

745745
Broadcasts the `DOMStorage.domStorageItemUpdated` event to connected frontends.
746746
This event indicates that a storage item has been updated.
@@ -759,7 +759,7 @@ added:
759759
* `isLocalStorage` {boolean}
760760

761761
This feature is only available with the
762-
`--experimental-inspector-storage-key=key` flag enabled.
762+
`--experimental-storage-inspection` flag enabled.
763763

764764
Broadcasts the `DOMStorage.domStorageItemsCleared` event to connected
765765
frontends. This event indicates that all items have been cleared from the
@@ -777,10 +777,7 @@ added:
777777
* `storageMap` {Object}
778778

779779
This feature is only available with the
780-
`--experimental-inspector-storage-key=key` flag enabled.
781-
782-
Registers a storage map with the inspector. The registered storage entries are
783-
reported when getDOMStorageItems is called.
780+
`--experimental-storage-inspection` flag enabled.
784781

785782
## Support of breakpoints
786783

doc/node.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Enable the experimental QUIC support.
232232
.It Fl -experimental-inspector-network-resource
233233
Enable experimental support for inspector network resources.
234234

235-
.It Fl -experimental-inspector-storage-key
235+
.It Fl -experimental-storage-inspection
236236
Specify a inspector storage key used by the Node.js inspector when connecting to Chrome DevTools.
237237

238238
.

src/inspector/storage_agent.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ void StorageAgent::Wire(protocol::UberDispatcher* dispatcher) {
1919
}
2020
DispatchResponse StorageAgent::getStorageKey(
2121
std::optional<protocol::String> frameId, protocol::String* storageKey) {
22-
*storageKey = env_->options()->experimental_inspector_storage_key;
22+
auto local_storage_file = env_->options()->localstorage_file;
23+
*storageKey = to_file_url(local_storage_file);
2324
return protocol::DispatchResponse::Success();
2425
}
2526

27+
std::string StorageAgent::to_file_url(const std::filesystem::path& input) {
28+
std::filesystem::path abs =
29+
std::filesystem::weakly_canonical(std::filesystem::absolute(input));
30+
return "file://" + abs.generic_string();
31+
}
32+
2633
} // namespace protocol
2734
} // namespace inspector
2835
} // namespace node

src/inspector/storage_agent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class StorageAgent : public protocol::Storage::Backend {
2626
private:
2727
std::unique_ptr<protocol::Storage::Frontend> frontend_;
2828
Environment* env_;
29+
std::string to_file_url(const std::filesystem::path& input);
2930
};
3031
} // namespace protocol
3132
} // namespace inspector

src/inspector_agent.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
265265
target_agent_->Wire(node_dispatcher_.get());
266266
target_agent_->listenWorker(worker_manager);
267267
}
268-
if (env->options()->experimental_inspector_storage_key.empty() == false) {
268+
if (env->options()->experimental_storage_inspection) {
269269
dom_storage_agent_ = std::make_unique<DOMStorageAgent>(env);
270270
dom_storage_agent_->Wire(node_dispatcher_.get());
271271
storage_agent_ = std::make_unique<protocol::StorageAgent>(env_);
@@ -308,7 +308,7 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
308308
network_inspector_->emitNotification(
309309
context, domain_name, event_name, params);
310310
} else if (dom_storage_agent_ && dom_storage_agent_->canEmit(domain_name) &&
311-
!env_->options()->experimental_inspector_storage_key.empty()) {
311+
env_->options()->experimental_storage_inspection) {
312312
dom_storage_agent_->emitNotification(context, event_name, params);
313313
}
314314
}

src/node_options.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
783783
AddOption("--experimental-network-inspection",
784784
"experimental network inspection support",
785785
&EnvironmentOptions::experimental_network_inspection);
786-
AddOption("--experimental-inspector-storage-key",
786+
AddOption("--experimental-storage-inspection",
787787
"experimental storage inspection support",
788-
&EnvironmentOptions::experimental_inspector_storage_key);
788+
&EnvironmentOptions::experimental_storage_inspection);
789789
AddOption("--experimental-worker-inspection",
790790
"experimental worker inspection support",
791791
&EnvironmentOptions::experimental_worker_inspection);

src/node_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class EnvironmentOptions : public Options {
176176
bool cpu_prof = false;
177177
bool experimental_network_inspection = false;
178178
bool experimental_worker_inspection = false;
179-
std::string experimental_inspector_storage_key;
179+
bool experimental_storage_inspection = false;
180180
bool experimental_inspector_network_resource = false;
181181
std::string heap_prof_dir;
182182
std::string heap_prof_name;

test/parallel/test-inspector-dom-storage.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// Flags: --inspect=0 --experimental-inspector-storage-key=node-inspector://default-dom-storage
1+
// Flags: --inspect=0 --experimental-storage-inspection --localstorage-file=./localstorage.db
22
'use strict';
33

44
const common = require('../common');
55
const assert = require('assert');
66
common.skipIfInspectorDisabled();
77
const { DOMStorage, Session } = require('node:inspector/promises');
8+
const { pathToFileURL } = require('node:url');
89

910

1011
async function test() {
@@ -13,6 +14,11 @@ async function test() {
1314

1415
await session.post('DOMStorage.enable');
1516

17+
const localStorageFileUrl = pathToFileURL('./localstorage.db').toString();
18+
19+
const { storageKey } = await session.post('Storage.getStorageKey');
20+
assert.strictEqual(storageKey, localStorageFileUrl);
21+
1622
await checkStorage(true);
1723
await checkStorage(false);
1824

test/parallel/test-inspector-emit-protocol-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --inspect=0 --experimental-network-inspection --experimental-inspector-storage-key=node-inspector://default-dom-storage
1+
// Flags: --inspect=0 --experimental-network-inspection --experimental-storage-inspection
22
'use strict';
33
const common = require('../common');
44

0 commit comments

Comments
 (0)