diff --git a/src/inspector/dom_storage_agent.cc b/src/inspector/dom_storage_agent.cc index 3708d3b59975..caf7ca98f7d3 100644 --- a/src/inspector/dom_storage_agent.cc +++ b/src/inspector/dom_storage_agent.cc @@ -101,10 +101,12 @@ protocol::DispatchResponse DOMStorageAgent::getDOMStorageItems( std::optional storage_map_fallback; if (storage_map->empty()) { auto web_storage_obj = getWebStorage(is_local_storage); - if (web_storage_obj) { - storage_map_fallback = web_storage_obj.value()->GetAll(); - storage_map = &storage_map_fallback.value(); + if (!web_storage_obj) { + return protocol::DispatchResponse::ServerError( + "Could not read DOM storage items"); } + storage_map_fallback = web_storage_obj.value()->GetAll(); + storage_map = &storage_map_fallback.value(); } auto result = diff --git a/test/parallel/test-inspector-dom-storage-unavailable.js b/test/parallel/test-inspector-dom-storage-unavailable.js new file mode 100644 index 000000000000..73db9ae00421 --- /dev/null +++ b/test/parallel/test-inspector-dom-storage-unavailable.js @@ -0,0 +1,31 @@ +// Flags: --experimental-storage-inspection --no-warnings +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const inspector = require('node:inspector/promises'); +const assert = require('node:assert'); + +(async () => { + const session = new inspector.Session(); + session.connect(); + + await session.post('DOMStorage.enable'); + + await assert.rejects( + session.post('DOMStorage.getDOMStorageItems', { + storageId: { + isLocalStorage: true, + securityOrigin: '', + storageKey: '', + }, + }), + { + code: 'ERR_INSPECTOR_COMMAND', + message: 'Inspector error -32000: Could not read DOM storage items', + }, + ); + + session.disconnect(); +})().then(common.mustCall());