webviewko
webviewko provides a Kotlin/JVM and a Kotlin/Native(experimental) binding to webview, a tiny cross-platform webview library to build modern cross-platform GUIs using WebView2, WebKit and WebKitGTK.
Getting Started
1. Import webviewko
If you're using a build system like Gradle or Maven, see webviewko in JitPack.io or GitHub Packages
If you want to use jar files, see GitHub Release
2. Use webviewko
For Kotlin/JVM and Kotlin/Native:
import com.github.winterreisender.webviewko.WebviewKo
WebviewKo().run {
title("Title")
size(800, 600)
url("https://example.com")
show()
}
For Java:
import com.github.winterreisender.webviewko.WebviewKo;
WebviewKo webview = new WebviewKo(0);
webview.title("Test");
webview.size(1024,768,WebviewKo.WindowHint.None);
webview.url("https://example.com");
webview.show();
3. Interact with webview
You can use bind
,init
,dispatch
and eval
to interact with your webview:
import com.github.winterreisender.webviewko.WebviewKo
WebviewKo().run {
title("Test")
init("""console.log("Hello, from init")""")
bind("increment") {
val r :Int = Regex("""\["(\d+)"]""").find(it!!)!!.groupValues[1].toInt() + 1
println(r.toString())
if(r==8) terminate()
"{count: $r}"
}
html("""
You tapped 0 time(s).
""".trimIndent())
show()
}
Documentation
- API Reference (KDoc)
- GitHub Wiki
- Examples
- Test (Kotlin/Multiplatform)
- TestKt (Kotlin/JVM)
- TestJava (Java)
- TestNative (Kotlin/Native)
- webview Documentation
Demos
A commandline interface: Winterreisender/webviewkoCLI
Contribution
All suggestions, pull requests, issues and other contributions are welcome and appreciated.
Credits
Project | License |
---|---|
wiverson/webviewjar | MIT |
webview_csharp | MIT |
webview | MIT |
JNA | LGPL-2.1-or-later OR Apache-2.0 |
Microsoft Webview2 | See the License |
Kotlin & kotlinx | Apache-2.0 |
License
Copyright 2022 Winterreisender and other contributors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
SPDX short identifier: Apache-2.0