Skip to content

Truly independent web browser

LibWeb+LibWebView+WebContent: Ask the UI process for text predictions

sideshowbarkerae2c3f8becfb
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 8a494220f52..5ac5f444aba 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2902,6 +2902,25 @@ GC::Ref<WebIDL::Promise> Internals::spell_check_settled()
return promise;
}
+GC::Ref<WebIDL::Promise> Internals::request_writing_suggestion_for_testing(Utf16String const& text, WebIDL::UnsignedLong caret_offset)
+{
+ auto& realm = window().principal_realm();
+ auto promise = WebIDL::create_promise_for(window());
+ auto& page = this->page();
+ if (!page.writing_suggestions_available()) {
+ WebIDL::reject_promise(realm, promise, JS::PrimitiveString::create(vm(), "Writing suggestions are unavailable"_utf16));
+ return promise;
+ }
+ page.request_writing_suggestion(text, caret_offset, GC::create_function(heap(), [&realm, promise](Optional<WritingSuggestion> suggestion) {
+ HTML::TemporaryExecutionContext execution_context { realm };
+ auto result = suggestion.has_value()
+ ? Utf16String::formatted("{}-{}:{}", suggestion->replacement_start, suggestion->replacement_length, suggestion->text)
+ : "(none)"_utf16;
+ WebIDL::resolve_promise(realm, promise, JS::PrimitiveString::create(realm.vm(), move(result)));
+ }));
+ return promise;
+}
+
GC::Ref<WebIDL::Promise> Internals::activate_spelling_menu_item(Bindings::SpellingMenuItem item, WebIDL::UnsignedLong guess_index)
{
auto& realm = window().principal_realm();
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 18968ca1834..c932a218930 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -88,6 +88,8 @@ public:
Utf16String spelling_error_ranges(GC::Ref<DOM::Node>);
GC::Ref<WebIDL::Promise> check_spelling_for_testing(Utf16String const& text);
GC::Ref<WebIDL::Promise> spell_check_settled();
+
+ GC::Ref<WebIDL::Promise> request_writing_suggestion_for_testing(Utf16String const& text, WebIDL::UnsignedLong caret_offset);
GC::Ref<WebIDL::Promise> activate_spelling_menu_item(Bindings::SpellingMenuItem, WebIDL::UnsignedLong guess_index);
void send_text(HTML::HTMLElement&, Utf16String const&, WebIDL::UnsignedShort modifiers);
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 3b8203e8e3e..d1fa0ac1824 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -50,6 +50,9 @@ interface Internals {
DOMString spellingErrorRanges(Node node);
Promise<DOMString> checkSpellingForTesting(DOMString text);
Promise<undefined> spellCheckSettled();
+
+ // Writing suggestions
+ Promise<DOMString> requestWritingSuggestionForTesting(DOMString text, unsigned long caretOffset);
Promise<DOMString> activateSpellingMenuItem(SpellingMenuItem item, optional unsigned long guessIndex = 0);
const unsigned short MOD_NONE = 0;
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 87da3cfae29..7ffbd0373cb 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -147,6 +147,7 @@ void Page::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_pending_clipboard_requests);
visitor.visit(m_pending_spell_check_requests);
visitor.visit(m_spell_checking_settled_callbacks);
+ visitor.visit(m_pending_writing_suggestion_requests);
visitor.visit(m_on_spelling_menu_action_for_testing);
visitor.visit(m_emulated_position_data);
visitor.visit(m_emulated_position_data_observers);
@@ -1340,6 +1341,19 @@ void Page::did_check_spelling(u64 request_id, Vector<SpellingError> errors)
notify_spell_check_progress();
}
+void Page::request_writing_suggestion(Utf16String const& text, u32 caret_offset, WritingSuggestionRequest request)
+{
+ auto request_id = m_next_writing_suggestion_request_id++;
+ m_pending_writing_suggestion_requests.set(request_id, request);
+ client().page_did_request_writing_suggestion(request_id, text, caret_offset);
+}
+
+void Page::did_get_writing_suggestion(u64 request_id, Optional<WritingSuggestion> suggestion)
+{
+ if (auto request = m_pending_writing_suggestion_requests.take(request_id); request.has_value())
+ (*request)->function()(move(suggestion));
+}
+
static bool spell_checking_is_settled(Page& page)
{
if (page.has_pending_spell_checks())
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 95e069c6dba..06cc84aae3d 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -93,6 +93,7 @@
#include <LibWebCommon/Page/SpellingError.h>
#include <LibWebCommon/Page/TextEditingCommand.h>
#include <LibWebCommon/Page/ViewportIsFullscreen.h>
+#include <LibWebCommon/Page/WritingSuggestion.h>
#include <LibWebCommon/PixelUnits.h>
#include <LibWebCommon/StorageAPI/StorageEndpoint.h>
#include <LibWebCommon/UIEvents/KeyCode.h>
@@ -320,6 +321,13 @@ public:
void when_spell_checking_settled(GC::Ref<GC::Function<void()>>);
void notify_spell_check_progress();
+ using WritingSuggestionRequest = GC::Ref<GC::Function<void(Optional<WritingSuggestion>)>>;
+ bool writing_suggestions_available() const { return m_writing_suggestions_available; }
+ void set_writing_suggestions_available(bool available) { m_writing_suggestions_available = available; }
+ void request_writing_suggestion(Utf16String const& text, u32 caret_offset, WritingSuggestionRequest);
+ void did_get_writing_suggestion(u64 request_id, Optional<WritingSuggestion>);
+ bool has_pending_writing_suggestions() const { return !m_pending_writing_suggestion_requests.is_empty(); }
+
using GeolocationPositionResult = Variant<Geolocation::CoordinatesData, Geolocation::GeolocationPositionError::ErrorCode>;
using GeolocationPositionCallback = GC::Ref<GC::Function<void(GeolocationPositionResult)>>;
enum class GeolocationRequestType : u8 {
@@ -553,6 +561,10 @@ private:
u64 m_next_spell_check_request_id { 0 };
Vector<GC::Ref<GC::Function<void()>>> m_spell_checking_settled_callbacks;
+ bool m_writing_suggestions_available { false };
+ HashMap<u64, WritingSuggestionRequest> m_pending_writing_suggestion_requests;
+ u64 m_next_writing_suggestion_request_id { 0 };
+
struct PendingGeolocationRequest {
GeolocationPositionCallback callback;
GeolocationRequestType type;
@@ -869,6 +881,7 @@ public:
virtual void page_did_insert_clipboard_item(Clipboard::SystemClipboardItem const&, [[maybe_unused]] StringView presentation_style) { }
virtual void page_did_request_clipboard_entries([[maybe_unused]] u64 request_id) { }
virtual void page_did_request_spell_check([[maybe_unused]] u64 request_id, [[maybe_unused]] Utf16String const& text) { }
+ virtual void page_did_request_writing_suggestion([[maybe_unused]] u64 request_id, [[maybe_unused]] Utf16String const& text, [[maybe_unused]] u32 caret_offset) { }
virtual void page_did_request_primary_paste() { }
virtual void page_did_complete_paste_action() { }
virtual void page_did_update_primary_selection(Utf16String const&) { }
diff --git a/Libraries/LibWebCommon/CMakeLists.txt b/Libraries/LibWebCommon/CMakeLists.txt
index 29fd96811a8..ffb126ecd59 100644
--- a/Libraries/LibWebCommon/CMakeLists.txt
+++ b/Libraries/LibWebCommon/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SOURCES
Page/InputTrace.cpp
Page/MediaContextMenu.cpp
Page/SpellingError.cpp
+ Page/WritingSuggestion.cpp
PermissionsPolicy/PermissionsPolicy.cpp
PixelUnits.cpp
ReferrerPolicy/ReferrerPolicy.cpp
diff --git a/Libraries/LibWebCommon/Page/WritingSuggestion.cpp b/Libraries/LibWebCommon/Page/WritingSuggestion.cpp
new file mode 100644
index 00000000000..6579b0b2a51
--- /dev/null
+++ b/Libraries/LibWebCommon/Page/WritingSuggestion.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibIPC/Decoder.h>
+#include <LibIPC/Encoder.h>
+#include <LibWebCommon/Page/WritingSuggestion.h>
+
+template<>
+ErrorOr<void> IPC::encode(Encoder& encoder, Web::WritingSuggestion const& suggestion)
+{
+ TRY(encoder.encode(suggestion.replacement_start));
+ TRY(encoder.encode(suggestion.replacement_length));
+ TRY(encoder.encode(suggestion.text));
+ return {};
+}
+
+template<>
+ErrorOr<Web::WritingSuggestion> IPC::decode(Decoder& decoder)
+{
+ auto replacement_start = TRY(decoder.decode<u32>());
+ auto replacement_length = TRY(decoder.decode<u32>());
+ auto text = TRY(decoder.decode<Utf16String>());
+ return Web::WritingSuggestion { replacement_start, replacement_length, move(text) };
+}
diff --git a/Libraries/LibWebCommon/Page/WritingSuggestion.h b/Libraries/LibWebCommon/Page/WritingSuggestion.h
new file mode 100644
index 00000000000..442365f9372
--- /dev/null
+++ b/Libraries/LibWebCommon/Page/WritingSuggestion.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Types.h>
+#include <AK/Utf16String.h>
+#include <LibIPC/Forward.h>
+#include <LibWebCommon/Export.h>
+
+namespace Web {
+
+// A predicted continuation of the text around the caret: The text replaces the UTF-16 code units
+// [replacement_start, replacement_start + replacement_length) of the text that was sent.
+struct WritingSuggestion {
+ u32 replacement_start { 0 };
+ u32 replacement_length { 0 };
+ Utf16String text;
+};
+
+}
+
+namespace IPC {
+
+template<>
+WEBCOMMON_API ErrorOr<void> encode(Encoder&, Web::WritingSuggestion const&);
+
+template<>
+WEBCOMMON_API ErrorOr<Web::WritingSuggestion> decode(Decoder&);
+
+}
diff --git a/Libraries/LibWebView/SpellChecker.h b/Libraries/LibWebView/SpellChecker.h
index 0a45c6f939a..782a659579f 100644
--- a/Libraries/LibWebView/SpellChecker.h
+++ b/Libraries/LibWebView/SpellChecker.h
@@ -10,6 +10,7 @@
#include <AK/Utf16String.h>
#include <AK/Vector.h>
#include <LibWebCommon/Page/SpellingError.h>
+#include <LibWebCommon/Page/WritingSuggestion.h>
#include <LibWebView/Export.h>
namespace WebView {
@@ -36,6 +37,16 @@ public:
// Whether a learned word holds for every document tag, as it does in a user dictionary that every app shares.
virtual bool learns_for_every_tag() const { return true; }
+
+ // Whether suggest() can ever answer, i.e. the platform predicts text as the user types.
+ virtual bool can_suggest() const { return false; }
+
+ // Predicts how the text could continue at caret_offset (in UTF-16 code units). Asynchronous; on_complete runs on
+ // the main thread, with nothing if there's no prediction.
+ virtual void suggest(DocumentTag, [[maybe_unused]] Utf16String const& text, [[maybe_unused]] u32 caret_offset, Function<void(Optional<Web::WritingSuggestion>)> on_complete)
+ {
+ on_complete({});
+ }
};
}
diff --git a/Libraries/LibWebView/TestSpellChecker.cpp b/Libraries/LibWebView/TestSpellChecker.cpp
index 34d922844b5..ceb79d5ca02 100644
--- a/Libraries/LibWebView/TestSpellChecker.cpp
+++ b/Libraries/LibWebView/TestSpellChecker.cpp
@@ -47,6 +47,20 @@ static bool is_word_code_unit(char16_t code_unit)
return is_ascii_alpha(code_unit) || code_unit == '\'';
}
+// What each word at the caret is predicted to become. The last one corrects what's typed rather than continuing it.
+// Every test-web test has these predictions, so a test that types one of these words and then waits before pressing Tab
+// accepts the prediction rather than moving focus.
+static Optional<StringView> prediction_for(Utf16View partial_word)
+{
+ if (partial_word == u"predi"sv)
+ return "prediction"sv;
+ if (partial_word == u"Lady"sv)
+ return "Ladybird browser"sv;
+ if (partial_word == u"teh"sv)
+ return "the"sv;
+ return {};
+}
+
SpellChecker::DocumentTag TestSpellChecker::create_document_tag()
{
return m_next_document_tag++;
@@ -88,6 +102,30 @@ void TestSpellChecker::check(DocumentTag tag, Utf16String const& text, Function<
});
}
+void TestSpellChecker::suggest(DocumentTag, Utf16String const& text, u32 caret_offset, Function<void(Optional<Web::WritingSuggestion>)> on_complete)
+{
+ Optional<Web::WritingSuggestion> suggestion;
+ auto view = text.utf16_view();
+ if (caret_offset <= view.length_in_code_units()) {
+ // The candidate replaces the whole word the caret is in, as platform spellcheckers' candidates do.
+ auto start = caret_offset;
+ while (start > 0 && is_word_code_unit(view.code_unit_at(start - 1)))
+ --start;
+ auto end = caret_offset;
+ while (end < view.length_in_code_units() && is_word_code_unit(view.code_unit_at(end)))
+ ++end;
+ if (start < caret_offset) {
+ if (auto prediction = prediction_for(view.substring_view(start, end - start)); prediction.has_value())
+ suggestion = Web::WritingSuggestion { start, end - start, Utf16String::from_utf8(*prediction) };
+ }
+ }
+
+ // Answer on a later turn of the event loop, as platform spellcheckers do.
+ Core::deferred_invoke([on_complete = move(on_complete), suggestion = move(suggestion)]() mutable {
+ on_complete(move(suggestion));
+ });
+}
+
Vector<Utf16String> TestSpellChecker::guesses(DocumentTag, Utf16String const& word)
{
return guesses_for(word.utf16_view());
diff --git a/Libraries/LibWebView/TestSpellChecker.h b/Libraries/LibWebView/TestSpellChecker.h
index b14d10d89c7..e3dc5ca43ed 100644
--- a/Libraries/LibWebView/TestSpellChecker.h
+++ b/Libraries/LibWebView/TestSpellChecker.h
@@ -22,6 +22,8 @@ public:
virtual void ignore(DocumentTag, Utf16String const& word) override;
virtual void learn(DocumentTag, Utf16String const& word) override;
virtual bool learns_for_every_tag() const override { return false; }
+ virtual bool can_suggest() const override { return true; }
+ virtual void suggest(DocumentTag, Utf16String const& text, u32 caret_offset, Function<void(Optional<Web::WritingSuggestion>)> on_complete) override;
private:
bool is_misspelled(DocumentTag, Utf16View word) const;
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 8c6e3c11562..6eb8e152343 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -1349,7 +1349,9 @@ void ViewImplementation::send_preferences_to_page(WebContentPage& page)
send_browsing_behavior(page);
send_autoplay_settings(page);
send_global_privacy_control(page);
- page.async_set_spell_checking_available(Application::the().spell_checker() != nullptr);
+ auto* spell_checker = Application::the().spell_checker();
+ page.async_set_spell_checking_available(spell_checker != nullptr);
+ page.async_set_writing_suggestions_available(spell_checker && spell_checker->can_suggest());
send_geolocation_emulated_position(page);
page.async_set_has_picture_in_picture_support(Application::the().supports_picture_in_picture());
}
@@ -4636,6 +4638,19 @@ void ViewImplementation::did_request_spell_check(Badge<WebContentPage>, WebConte
});
}
+void ViewImplementation::did_request_writing_suggestion(Badge<WebContentPage>, WebContentPage& requesting_page, u64 request_id, Utf16String text, u32 caret_offset)
+{
+ auto* spell_checker = Application::the().spell_checker();
+ if (!spell_checker) {
+ requesting_page.async_did_get_writing_suggestion(request_id, {});
+ return;
+ }
+ spell_checker->suggest(spell_document_tag(), text, caret_offset, [page = NonnullRefPtr { requesting_page }, request_id](Optional<Web::WritingSuggestion> suggestion) {
+ if (page->is_open())
+ page->async_did_get_writing_suggestion(request_id, move(suggestion));
+ });
+}
+
// Forgets what the user told the spellchecker to ignore or learn in this tab.
void ViewImplementation::reset_spell_checking()
{
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 3bd340b1fa1..bcbf5f5471d 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -595,6 +595,7 @@ public:
void activate_spelling_menu_action_for_testing(Badge<WebContentPage>, WebContentPage& requesting_page, Web::SpellingMenuActionForTesting, u32 guess_index);
void did_request_spell_check(Badge<WebContentPage>, WebContentPage& requesting_page, u64 request_id, Utf16String text);
+ void did_request_writing_suggestion(Badge<WebContentPage>, WebContentPage& requesting_page, u64 request_id, Utf16String text, u32 caret_offset);
void reset_spell_checking();
void did_request_link_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor, Optional<u64> text_fragment_generation_id);
void did_generate_text_fragment_url(u64 request_id, Optional<URL::URL>);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 2930cfbaa96..abf0fa2510b 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1932,6 +1932,11 @@ void WebContentPage::did_request_spell_check(u64 request_id, Utf16String text)
view().did_request_spell_check({}, *this, request_id, move(text));
}
+void WebContentPage::did_request_writing_suggestion(u64 request_id, Utf16String text, u32 caret_offset)
+{
+ view().did_request_writing_suggestion({}, *this, request_id, move(text), caret_offset);
+}
+
void WebContentPage::did_request_set_system_focus(bool has_system_focus)
{
traversable().set_has_system_focus(has_system_focus, *this);
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 0b502616da8..0784ede91b1 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -299,6 +299,7 @@ private:
virtual void did_update_indexed_database(String update) override;
virtual void did_request_clipboard_entries(u64 request_id) override;
virtual void did_request_spell_check(u64 request_id, Utf16String text) override;
+ virtual void did_request_writing_suggestion(u64 request_id, Utf16String text, u32 caret_offset) override;
virtual void did_request_set_system_focus(bool has_system_focus) override;
virtual void did_request_set_system_visibility_state(Web::HTML::VisibilityState visibility_state) override;
virtual void did_request_navigation_start(Web::HTML::CrossProcessId navigable_id, Web::NavigationTarget target, URL::URL url, Utf16String navigation_id, Optional<Web::HTML::NavigationStartRequest> start_request) override;
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 2c53d21ca77..50aff8bab0b 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -3422,6 +3422,18 @@ void ConnectionFromClient::did_check_spelling(Web::PageId page_id, u64 request_i
page->page().did_check_spelling(request_id, move(errors));
}
+void ConnectionFromClient::set_writing_suggestions_available(Web::PageId page_id, bool available)
+{
+ if (auto page = this->page(page_id); page.has_value())
+ page->page().set_writing_suggestions_available(available);
+}
+
+void ConnectionFromClient::did_get_writing_suggestion(Web::PageId page_id, u64 request_id, Optional<Web::WritingSuggestion> suggestion)
+{
+ if (auto page = this->page(page_id); page.has_value())
+ page->page().did_get_writing_suggestion(request_id, move(suggestion));
+}
+
void ConnectionFromClient::replace_context_menu_misspelling(Web::PageId page_id, Utf16String replacement)
{
if (auto page = this->page(page_id); page.has_value())
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index 4c676c5a01d..5cc8b6bd87e 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -251,6 +251,7 @@ private:
virtual void set_browsing_behavior(Web::PageId page_id, WebView::BrowsingBehavior) override;
virtual void set_enable_global_privacy_control(Web::PageId page_id, bool) override;
virtual void set_spell_checking_available(Web::PageId page_id, bool available) override;
+ virtual void set_writing_suggestions_available(Web::PageId page_id, bool available) override;
virtual void set_geolocation_emulated_position(Web::PageId page_id, WebView::GeolocationPositionData, Optional<u16> error_code) override;
virtual void geolocation_position_response(Web::PageId page_id, u64 request_id, WebView::GeolocationPositionData, Optional<u16> error_code) override;
virtual void permission_request_completed(Web::PageId page_id, u64 request_id, bool granted) override;
@@ -286,6 +287,7 @@ private:
virtual void retrieved_clipboard_entries(Web::PageId page_id, u64 request_id, Vector<Web::Clipboard::SystemClipboardItem>) override;
virtual void did_check_spelling(Web::PageId page_id, u64 request_id, Vector<Web::SpellingError> errors) override;
+ virtual void did_get_writing_suggestion(Web::PageId page_id, u64 request_id, Optional<Web::WritingSuggestion> suggestion) override;
virtual void replace_context_menu_misspelling(Web::PageId page_id, Utf16String replacement) override;
virtual void accept_spelling_word(Web::PageId page_id, Utf16String word) override;
virtual void forget_accepted_spelling_words(Web::PageId page_id) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 50b099d5834..4e4ceee64a0 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -1935,6 +1935,11 @@ void PageClient::page_did_request_spell_check(u64 request_id, Utf16String const&
client().async_did_request_spell_check(m_id, request_id, text);
}
+void PageClient::page_did_request_writing_suggestion(u64 request_id, Utf16String const& text, u32 caret_offset)
+{
+ client().async_did_request_writing_suggestion(m_id, request_id, text, caret_offset);
+}
+
void PageClient::page_did_request_primary_paste()
{
client().async_did_request_primary_paste(m_id);
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 8a296b1ebe3..77d4a7e5d96 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -357,6 +357,7 @@ private:
virtual void page_did_insert_clipboard_item(Web::Clipboard::SystemClipboardItem const&, StringView presentation_style) override;
virtual void page_did_request_clipboard_entries(u64 request_id) override;
virtual void page_did_request_spell_check(u64 request_id, Utf16String const& text) override;
+ virtual void page_did_request_writing_suggestion(u64 request_id, Utf16String const& text, u32 caret_offset) override;
virtual void page_did_request_primary_paste() override;
virtual void page_did_complete_paste_action() override;
virtual void page_did_update_primary_selection(Utf16String const&) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index 2a7370a277d..5ab4f8c082c 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -60,6 +60,7 @@
#include <LibWebCommon/Page/PendingDialog.h>
#include <LibWebCommon/Page/ScreenWakeLockState.h>
#include <LibWebCommon/Page/SpellingError.h>
+#include <LibWebCommon/Page/WritingSuggestion.h>
#include <LibWebCommon/ReferrerPolicy/ReferrerPolicy.h>
#include <LibWebCommon/StorageAPI/StorageAreaId.h>
#include <LibWebCommon/StorageAPI/StorageEndpoint.h>
@@ -244,6 +245,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_insert_clipboard_item(Web::PageId page_id, Web::Clipboard::SystemClipboardItem item, String presentation_style) =|
did_request_clipboard_entries(Web::PageId page_id, u64 request_id) =|
did_request_spell_check(Web::PageId page_id, u64 request_id, Utf16String text) =|
+ did_request_writing_suggestion(Web::PageId page_id, u64 request_id, Utf16String text, u32 caret_offset) =|
did_request_primary_paste(Web::PageId page_id) =|
did_update_primary_selection(Web::PageId page_id, String text) =|
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 3fcf8dfafa8..6d2a1cceb69 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -48,6 +48,7 @@
#include <LibWebCommon/Page/PageId.h>
#include <LibWebCommon/Page/PendingDialog.h>
#include <LibWebCommon/Page/SpellingError.h>
+#include <LibWebCommon/Page/WritingSuggestion.h>
#include <LibWebCommon/Page/ViewportIsFullscreen.h>
#include <LibWebCommon/ReferrerPolicy/ReferrerPolicy.h>
#include <LibWebCommon/StorageAPI/StorageAreaId.h>
@@ -256,6 +257,7 @@ endpoint WebContentServer routed by Web::PageId page_id
set_browsing_behavior(Web::PageId page_id, WebView::BrowsingBehavior browsing_behavior) =|
set_enable_global_privacy_control(Web::PageId page_id, bool enable) =|
set_spell_checking_available(Web::PageId page_id, bool available) =|
+ set_writing_suggestions_available(Web::PageId page_id, bool available) =|
set_geolocation_emulated_position(Web::PageId page_id, WebView::GeolocationPositionData position, Optional<u16> error_code) =|
geolocation_position_response(Web::PageId page_id, u64 request_id, WebView::GeolocationPositionData position, Optional<u16> error_code) =|
permission_request_completed(Web::PageId page_id, u64 request_id, bool granted) =|
@@ -290,6 +292,7 @@ endpoint WebContentServer routed by Web::PageId page_id
retrieved_clipboard_entries(Web::PageId page_id, u64 request_id, Vector<Web::Clipboard::SystemClipboardItem> items) =|
did_check_spelling(Web::PageId page_id, u64 request_id, Vector<Web::SpellingError> errors) =|
+ did_get_writing_suggestion(Web::PageId page_id, u64 request_id, Optional<Web::WritingSuggestion> suggestion) =|
replace_context_menu_misspelling(Web::PageId page_id, Utf16String replacement) =|
accept_spelling_word(Web::PageId page_id, Utf16String word) =|
forget_accepted_spelling_words(Web::PageId page_id) =|
diff --git a/Tests/LibWeb/Text/expected/Editing/writing-suggestion-source.txt b/Tests/LibWeb/Text/expected/Editing/writing-suggestion-source.txt
new file mode 100644
index 00000000000..c1b03287732
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Editing/writing-suggestion-source.txt
@@ -0,0 +1,5 @@
+7-5:prediction
+0-4:Ladybird browser
+0-3:the
+0-5:prediction
+(none)
diff --git a/Tests/LibWeb/Text/input/Editing/writing-suggestion-source.html b/Tests/LibWeb/Text/input/Editing/writing-suggestion-source.html
new file mode 100644
index 00000000000..3416e26ffd0
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Editing/writing-suggestion-source.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ println(await internals.requestWritingSuggestionForTesting("I like predi", 12));
+ println(await internals.requestWritingSuggestionForTesting("Lady", 4));
+ println(await internals.requestWritingSuggestionForTesting("teh", 3));
+ println(await internals.requestWritingSuggestionForTesting("predi", 2));
+ println(await internals.requestWritingSuggestionForTesting("predi ", 6));
+ });
+</script>