Skip to content

Commit

Permalink
LibWebView: Protect the Inspector against rapid inspection requests
Browse files Browse the repository at this point in the history
This was seen in Browser when hotkey activations were processed twice.
If we open the Inspector with a hotkey (F12) and quickly activate that
hotkey again, we could try sending a JS command (inspector.loadDOMTree)
before the inspector.js file was actually loaded in the WebContent.

The window for this bug is larger on Serenity, where loading WebContent
is a bit slower than on Linux. So even with the Browser bug fixed, it is
pretty easy to hit this window still.
  • Loading branch information
trflynn89 authored and awesomekling committed Mar 4, 2024
1 parent d392375 commit 552f63a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWebView/InspectorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple
m_inspector_web_view.use_native_user_style_sheet();

m_inspector_web_view.on_inspector_loaded = [this]() {
m_inspector_loaded = true;
inspect();

m_content_web_view.js_console_request_messages(0);
Expand Down Expand Up @@ -191,6 +192,8 @@ InspectorClient::~InspectorClient()

void InspectorClient::inspect()
{
if (!m_inspector_loaded)
return;
if (m_dom_tree_loaded)
return;

Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWebView/InspectorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class InspectorClient {
Optional<i32> m_body_node_id;
Optional<i32> m_pending_selection;

bool m_inspector_loaded { false };
bool m_dom_tree_loaded { false };

struct ContextMenuData {
Expand Down

0 comments on commit 552f63a

Please sign in to comment.