@@ -56,7 +56,7 @@ class ChromeWatcher : AccessibilityService() {
5656 }
5757
5858 try {
59- if (event != null && event .source != null ) {
59+ if (event.source != null ) {
6060 // Get URL
6161 val urlBars = event.source!! .findAccessibilityNodeInfosByViewId(" com.android.chrome:id/url_bar" )
6262 if (urlBars.any()) {
@@ -65,10 +65,13 @@ class ChromeWatcher : AccessibilityService() {
6565 }
6666
6767 // Get title
68- var webView = findWebView(event.source!! )
68+ val webView = findWebView(event.source!! )
6969 if (webView != null ) {
70- lastTitle = webView.text.toString()
71- Log .i(TAG , " Title: ${lastTitle} " )
70+ val title = webView.text.toString()
71+ if (title != lastTitle) {
72+ lastTitle = title
73+ Log .i(TAG , " Title: ${lastTitle} " )
74+ }
7275 }
7376 }
7477 }
@@ -78,9 +81,6 @@ class ChromeWatcher : AccessibilityService() {
7881 }
7982
8083 fun findWebView (info : AccessibilityNodeInfo ) : AccessibilityNodeInfo ? {
81- if (info == null )
82- return null
83-
8484 if (info.className == " android.webkit.WebView" && info.text != null )
8585 return info
8686
@@ -90,17 +90,17 @@ class ChromeWatcher : AccessibilityService() {
9090 if (webView != null ) {
9191 return webView
9292 }
93- if (child != null ){
94- child.recycle()
95- }
93+ child?.recycle()
9694 }
9795
9896 return null
9997 }
10098
10199 fun onUrl (newUrl : String? ) {
102- Log .i(TAG , " Url: ${newUrl} " )
103100 if (newUrl != lastUrl) { // URL changed
101+ if (newUrl != null ) {
102+ Log .i(TAG , " Url: $newUrl " )
103+ }
104104 if (lastUrl != null ) {
105105 // Log last URL and title as a completed browser event.
106106 // We wait for the event to complete (marked by a change in URL) to ensure that
0 commit comments