1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 21:55:07 +00:00

Browser: Add JS Console

The JavaScript console can be opened with Control+I, or using
the menu option. The console is currently a text box with JS
syntax highlighting which will send commands to the document's
interpreter. All output is printed to an HTML view in the console.
The output is an HtmlView to easily allow complex output, such
as expandable views for JS Objects in the long run.
This commit is contained in:
FalseHonesty 2020-05-23 12:53:09 -04:00 committed by Andreas Kling
parent 5e45d68442
commit 391237a8e1
8 changed files with 518 additions and 5 deletions

View file

@ -26,8 +26,8 @@
#include "Tab.h"
#include "BookmarksBarWidget.h"
#include "ConsoleWidget.h"
#include "DownloadWidget.h"
#include "History.h"
#include "InspectorWidget.h"
#include "WindowActions.h"
#include <AK/StringBuilder.h>
@ -44,7 +44,7 @@
#include <LibGUI/ToolBar.h>
#include <LibGUI/ToolBarContainer.h>
#include <LibGUI/Window.h>
#include <LibWeb/CSS/StyleResolver.h>
#include <LibJS/Interpreter.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOMTreeModel.h>
#include <LibWeb/Dump.h>
@ -55,7 +55,6 @@
#include <LibWeb/Layout/LayoutInline.h>
#include <LibWeb/Layout/LayoutNode.h>
#include <LibWeb/Parser/CSSParser.h>
#include <LibWeb/Parser/HTMLParser.h>
#include <LibWeb/ResourceLoader.h>
namespace Browser {
@ -285,6 +284,21 @@ Tab::Tab()
},
this));
inspect_menu.add_action(GUI::Action::create(
"Open JS Console", { Mod_Ctrl, Key_I }, [this](auto&) {
if (!m_console_window) {
m_console_window = GUI::Window::construct();
m_console_window->set_rect(100, 100, 500, 300);
m_console_window->set_title("JS Console");
m_console_window->set_main_widget<ConsoleWidget>();
}
auto* console_widget = static_cast<ConsoleWidget*>(m_console_window->main_widget());
console_widget->set_interpreter(m_html_widget->document()->interpreter().make_weak_ptr());
m_console_window->show();
m_console_window->move_to_front();
},
this));
auto& debug_menu = m_menubar->add_menu("Debug");
debug_menu.add_action(GUI::Action::create(
"Dump DOM tree", [this](auto&) {