mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
Browser: Add debug command to dump cookies
Using document.cookie only lets the test page see the name/value pair; the value returned will not included the parsed attributes.
This commit is contained in:
parent
fc03f8d959
commit
5496d71e4a
5 changed files with 37 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include "CookieJar.h"
|
#include "CookieJar.h"
|
||||||
#include <AK/AllOf.h>
|
#include <AK/AllOf.h>
|
||||||
#include <AK/NumericLimits.h>
|
#include <AK/NumericLimits.h>
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
@ -77,6 +78,32 @@ void CookieJar::set_cookie(const URL& url, const String& cookie_string)
|
||||||
it->value.append(move(*new_cookie));
|
it->value.append(move(*new_cookie));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CookieJar::dump_cookies() const
|
||||||
|
{
|
||||||
|
static const char* url_color = "\033[34;1m";
|
||||||
|
static const char* cookie_color = "\033[31m";
|
||||||
|
static const char* attribute_color = "\033[33m";
|
||||||
|
static const char* no_color = "\033[0m";
|
||||||
|
|
||||||
|
StringBuilder builder;
|
||||||
|
builder.appendff("{} URLs with cookies\n", m_cookies.size());
|
||||||
|
|
||||||
|
for (const auto& url_and_cookies : m_cookies) {
|
||||||
|
builder.appendff("{}Cookies for:{} {}\n", url_color, no_color, url_and_cookies.key.is_empty() ? "file://" : url_and_cookies.key);
|
||||||
|
|
||||||
|
for (const auto& cookie : url_and_cookies.value) {
|
||||||
|
builder.appendff("\t{}{}{} = {}{}{}\n", cookie_color, cookie.name, no_color, cookie_color, cookie.value, no_color);
|
||||||
|
builder.appendff("\t\t{}Expiry{} = {}\n", attribute_color, no_color, cookie.expiry_time.to_string());
|
||||||
|
builder.appendff("\t\t{}Domain{} = {}\n", attribute_color, no_color, cookie.domain);
|
||||||
|
builder.appendff("\t\t{}Path{} = {}\n", attribute_color, no_color, cookie.path);
|
||||||
|
builder.appendff("\t\t{}Secure{} = {:s}\n", attribute_color, no_color, cookie.secure);
|
||||||
|
builder.appendff("\t\t{}HttpOnly{} = {:s}\n", attribute_color, no_color, cookie.http_only);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln("{}", builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
Optional<String> CookieJar::canonicalize_domain(const URL& url)
|
Optional<String> CookieJar::canonicalize_domain(const URL& url)
|
||||||
{
|
{
|
||||||
// https://tools.ietf.org/html/rfc6265#section-5.1.2
|
// https://tools.ietf.org/html/rfc6265#section-5.1.2
|
||||||
|
|
|
@ -48,6 +48,7 @@ class CookieJar {
|
||||||
public:
|
public:
|
||||||
String get_cookie(const URL& url) const;
|
String get_cookie(const URL& url) const;
|
||||||
void set_cookie(const URL& url, const String& cookie);
|
void set_cookie(const URL& url, const String& cookie);
|
||||||
|
void dump_cookies() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Optional<String> canonicalize_domain(const URL& url);
|
static Optional<String> canonicalize_domain(const URL& url);
|
||||||
|
|
|
@ -440,6 +440,10 @@ Tab::Tab(Type type)
|
||||||
debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, [&](auto&) {
|
debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, [&](auto&) {
|
||||||
m_history.dump();
|
m_history.dump();
|
||||||
}));
|
}));
|
||||||
|
debug_menu.add_action(GUI::Action::create("Dump C&ookies", [&](auto&) {
|
||||||
|
if (on_dump_cookies)
|
||||||
|
on_dump_cookies();
|
||||||
|
}));
|
||||||
debug_menu.add_separator();
|
debug_menu.add_separator();
|
||||||
auto line_box_borders_action = GUI::Action::create_checkable(
|
auto line_box_borders_action = GUI::Action::create_checkable(
|
||||||
"&Line Box Borders", [this](auto& action) {
|
"&Line Box Borders", [this](auto& action) {
|
||||||
|
|
|
@ -72,6 +72,7 @@ public:
|
||||||
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||||
Function<String(const URL& url)> on_get_cookie;
|
Function<String(const URL& url)> on_get_cookie;
|
||||||
Function<void(const URL& url, const String& cookie)> on_set_cookie;
|
Function<void(const URL& url, const String& cookie)> on_set_cookie;
|
||||||
|
Function<void()> on_dump_cookies;
|
||||||
|
|
||||||
const String& title() const { return m_title; }
|
const String& title() const { return m_title; }
|
||||||
const Gfx::Bitmap* icon() const { return m_icon; }
|
const Gfx::Bitmap* icon() const { return m_icon; }
|
||||||
|
|
|
@ -227,6 +227,10 @@ int main(int argc, char** argv)
|
||||||
cookie_jar.set_cookie(url, cookie);
|
cookie_jar.set_cookie(url, cookie);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
new_tab.on_dump_cookies = [&]() {
|
||||||
|
cookie_jar.dump_cookies();
|
||||||
|
};
|
||||||
|
|
||||||
new_tab.load(url);
|
new_tab.load(url);
|
||||||
|
|
||||||
dbgln("Added new tab {:p}, loading {}", &new_tab, url);
|
dbgln("Added new tab {:p}, loading {}", &new_tab, url);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue