Skip to content

Natives

This page documents how the native API works


Saucer offers access to underlying platform data via its Native-API. This can be used to implement certain features that saucer does not support out of the box.

To get started, link against the saucer::private target to get access to all required headers and libraries.

Example: Linking private module
target_link_libraries(${PROJECT_NAME} [PRIVATE|PUBLIC] saucer::private)

Not all classes support the Native-API, but those that do expose a native member function.

Example: Native Access
auto native = webview->native();

Usually, one would use the “stable” natives, because their layout is guaranteed to be fairly stable.
To use the stable natives, include the respective header for your platform, which can be found in <saucer/modules/stable/{qt, webkit, webkitgtk, webview2}.hpp>.

Example: Stable Natives (Qt Backend)
#include <saucer/modules/stable/qt.hpp>
3 collapsed lines
coco::stray start(saucer::application *)
{
// ...
auto native = webview->native();
native.webview->setZoomFactor(5);
2 collapsed lines
// ...
}

You can also access a classes’ impl directly by calling native<false>(). This is mainly used within the official modules and not recommended for normal use due to its unstable nature. To use the unstable natives, include the respective private header.

Example: Unstable Natives (Qt Backend)
#include <saucer/qt.webview.impl.hpp>
3 collapsed lines
coco::stray start(saucer::application *)
{
// ...
auto *const native = webview->native<false>();
native->platform->web_page->setAudioMuted(true);
2 collapsed lines
// ...
}