Skip to content

Commit

Permalink
Disable text selection in webview
Browse files Browse the repository at this point in the history
  • Loading branch information
louischan-oursky committed Mar 8, 2024
2 parents ad551e9 + 921ce7a commit bfbec1c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sdk/src/main/java/com/oursky/authgear/WebKitWebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ class WebKitWebViewActivity: AppCompatActivity() {
private class MyWebViewClient constructor(private val activity: WebKitWebViewActivity) :
WebViewClient() {

companion object {
private const val USERSCRIPT_USER_SELECT_NONE = "document.documentElement.style.webkitUserSelect='none';document.documentElement.style.userSelect='none';";
}

override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
// android.webkit.view does not have WKUserContentController that allows us to inject userscript.
// onPageFinished will be called for each navigation.
// So it can be used as a replacement of WKUserContentController to allow us to
// run a script for every page.
// The caveat is that the script is run in the main frame only.
// But we do not actually use iframes so it does not matter.
view?.evaluateJavascript(USERSCRIPT_USER_SELECT_NONE, null);
}

@TargetApi(Build.VERSION_CODES.N)
override fun shouldOverrideUrlLoading(
view: WebView?,
Expand Down

0 comments on commit bfbec1c

Please sign in to comment.