Skip to content

Commit

Permalink
Browser+LibWeb: Add "Dump Local Storage" item to Browser's Debug menu
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Feb 8, 2022
1 parent 4797999 commit 3f9fc0f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Userland/Applications/Browser/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ void BrowserWindow::build_menus()
if (tab.on_dump_cookies)
tab.on_dump_cookies();
}));
debug_menu.add_action(GUI::Action::create("Dump &Local Storage", [this](auto&) {
active_tab().m_web_content_view->debug_request("dump-local-storage");
}));
debug_menu.add_separator();
auto line_box_borders_action = GUI::Action::create_checkable(
"Line &Box Borders", [this](auto& action) {
Expand Down
10 changes: 10 additions & 0 deletions Userland/Libraries/LibWeb/HTML/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,14 @@ Vector<String> Storage::supported_property_names() const
return m_map.keys();
}

void Storage::dump() const
{
dbgln("Storage ({} key(s))", m_map.size());
size_t i = 0;
for (auto const& it : m_map) {
dbgln("[{}] \"{}\": \"{}\"", i, it.key, it.value);
++i;
}
}

}
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/HTML/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Storage

Vector<String> supported_property_names() const;

void dump() const;

private:
Storage();

Expand Down
7 changes: 7 additions & 0 deletions Userland/Services/WebContent/ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Dump.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/Storage.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Loader/ContentFilter.h>
#include <LibWeb/Loader/ResourceLoader.h>
Expand Down Expand Up @@ -222,6 +224,11 @@ void ClientConnection::debug_request(const String& request, const String& argume
if (request == "same-origin-policy") {
m_page_host->page().set_same_origin_policy_enabled(argument == "on");
}

if (request == "dump-local-storage") {
if (auto* doc = page().top_level_browsing_context().active_document())
doc->window().local_storage()->dump();
}
}

void ClientConnection::get_source()
Expand Down

0 comments on commit 3f9fc0f

Please sign in to comment.