Jcef-compose is a small API targeting jvm that offers the ability to embed a CEF Browser as a Composable. The project was born because of Swing interoperability limitations; indeed, it is currently not possible to compose on top of a swing component (#1521, #2926).
Initially, the goal was to take advantage of the CEF OSR feature to render in Canvas
like in this experimental project,
but the performance was not up to par.
Ultimately, the project focuses on making it easy to integrate JCEF into a new or existing application using jcefmaven
while providing a lightweight and robust API.
Waiting for the JetBrains team and other compose contributors to provide an answer to Swing interoperability issue(s) (they will, sure).
- Java 11 or later
- Windows, OSR is not supported on arm64
- macOS
- Linux
Coming soon
Synchronous Cef
initialization example:
fun main() {
// https://github.com/JetBrains/compose-multiplatform/issues/2939
// The issue above will affect the window resizing and closing
Cef.initSync()
singleWindowApplication(
title = "CEF Compose Browser",
exitProcessOnExit = false
) {
CefBrowserCompose(
url = remember { "https://github.com/Manriif/jcef-compose" },
window = window,
initContent = { CefInitProgressContent(it) },
errorContent = { CefInitErrorContent(it) }
)
}
Cef.dispose()
exitProcess(0)
}
Asynchronous Cef
initialization example:
fun main() = disposableSingleWindowApplication(
title = "CEF Awt Browser",
onExitProcess = Cef::dispose
) {
val applicationDisposer = ApplicationDisposer.current
// https://github.com/JetBrains/compose-multiplatform/issues/2939
// Initializing asynchronously here fix the issue above without blocking the main thread
Cef.initAsync(onRestartRequired = applicationDisposer::restart)
CefBrowserAwt(
url = remember { "https://github.com/Manriif/jcef-compose" },
initContent = { CefInitProgressContent(it) },
errorContent = { CefInitErrorContent(it) }
)
}
Ready to run examples are available here.
These examples can be run on IntelliJ through run configurations.
Or as gradle tasks in the terminal:
./gradlew awt-browser
, example usage ofCefBrowserAwt
../gradlew compose-browser
, example usage ofCefBrowserCompose
../gradlew local-awt-browser
, example usage ofCefBrowserAwt
with local HTML, CSS and JS files../gradlew local-compose-browser
, example usage ofCefBrowserCompose
with local HTML, CSS and JS files.
Jcef limitations apply to this project, see:
Feel free to contribute!!