1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

Browser: Reconnect the JS console when the current page changes

Previously, it would keep a pointer to the interpreter of the previous
page, which resulted in Crashy Fun Times.

This also changes the clearing behavior - instead of clearing the
console output every time the window is shown, we clear it when the page
changes. This is more useful, since before you would lose any log
messages that had happened before opening the window.
This commit is contained in:
Sam Atkins 2021-09-01 17:21:48 +01:00 committed by Andreas Kling
parent 2b2158595f
commit ca2c129923

View file

@ -178,11 +178,19 @@ Tab::Tab(BrowserWindow& window)
if (m_dom_inspector_widget)
m_dom_inspector_widget->clear_dom_json();
if (m_console_widget)
m_console_widget->clear_output();
};
hooks().on_load_finish = [this](auto&) {
if (m_dom_inspector_widget)
m_web_content_view->inspect_dom_tree();
// FIXME: This is called after the page has finished loading, which means any log messages
// that happen *while* it is loading (such as inline <script>s) will be lost.
if (m_console_widget)
m_web_content_view->js_console_initialize();
};
hooks().on_link_click = [this](auto& url, auto& target, unsigned modifiers) {
@ -512,11 +520,9 @@ void Tab::show_console_window()
m_console_widget->on_js_input = [this](String const& js_source) {
m_web_content_view->js_console_input(js_source);
};
m_web_content_view->js_console_initialize();
}
m_console_widget->clear_output();
m_web_content_view->js_console_initialize();
auto* window = m_console_widget->window();
window->show();
window->move_to_front();