mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 08:45:09 +00:00
LibWeb+WebContent: Setup the js console client earlier
This allows us to print messages in inline scripts. Also add an example of this in the welcome page to test this.
This commit is contained in:
parent
446a10a1ac
commit
4912b22e3b
6 changed files with 15 additions and 3 deletions
|
@ -41,6 +41,9 @@
|
|||
column-width: 250px;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
console.log('Hello from an inline script in the head of welcome.html');
|
||||
</script>
|
||||
<script src="welcome.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
document.addEventListener("DOMContentLoaded", function () {
|
||||
console.log(
|
||||
"Hello from DOMContentLoaded! There should be a message before this from an inline script"
|
||||
);
|
||||
document.getElementById("ua").innerHTML = navigator.userAgent;
|
||||
});
|
||||
|
|
|
@ -398,6 +398,8 @@ void FrameLoader::resource_did_load()
|
|||
document->set_content_type(resource()->mime_type());
|
||||
|
||||
browsing_context().set_active_document(document);
|
||||
if (auto* page = browsing_context().page())
|
||||
page->client().page_did_create_main_document();
|
||||
|
||||
if (!parse_document(*document, resource()->encoded_data())) {
|
||||
load_error_page(url, "Failed to parse content.");
|
||||
|
|
|
@ -86,6 +86,7 @@ public:
|
|||
virtual CSS::PreferredColorScheme preferred_color_scheme() const = 0;
|
||||
virtual void page_did_change_title(String const&) { }
|
||||
virtual void page_did_start_loading(const AK::URL&) { }
|
||||
virtual void page_did_create_main_document() { }
|
||||
virtual void page_did_finish_loading(const AK::URL&) { }
|
||||
virtual void page_did_change_selection() { }
|
||||
virtual void page_did_request_cursor_change(Gfx::StandardCursor) { }
|
||||
|
|
|
@ -187,11 +187,13 @@ void PageHost::page_did_start_loading(const URL& url)
|
|||
m_client.async_did_start_loading(url);
|
||||
}
|
||||
|
||||
void PageHost::page_did_create_main_document()
|
||||
{
|
||||
m_client.initialize_js_console({});
|
||||
}
|
||||
|
||||
void PageHost::page_did_finish_loading(const URL& url)
|
||||
{
|
||||
// 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.
|
||||
m_client.initialize_js_console({});
|
||||
m_client.async_did_finish_loading(url);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
virtual void page_did_request_context_menu(Gfx::IntPoint const&) override;
|
||||
virtual void page_did_request_link_context_menu(Gfx::IntPoint const&, const URL&, String const& target, unsigned modifiers) override;
|
||||
virtual void page_did_start_loading(const URL&) override;
|
||||
virtual void page_did_create_main_document() override;
|
||||
virtual void page_did_finish_loading(const URL&) override;
|
||||
virtual void page_did_request_alert(String const&) override;
|
||||
virtual bool page_did_request_confirm(String const&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue