Skip to content

Commit 245ddd8

Browse files
committed
fix: prevent duplicate onPageFinished events for PDF.js viewer
1 parent ecffb88 commit 245ddd8

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,18 @@ class OSIABWebViewActivity : AppCompatActivity() {
357357
}
358358
}
359359

360+
var lastPageFinishedUrl: String? = null
361+
360362
override fun onPageFinished(view: WebView?, url: String?) {
363+
if (url != null && url == lastPageFinishedUrl && url.startsWith(PDF_VIEWER_URL_PREFIX)) {
364+
// If the url is the same as the last finished URL and it is a PDF viewer URL,
365+
// we do not want to trigger the page finished event again.
366+
// This prevents the event from being sent multiple times
367+
// since PDF.js triggers onPageFinished multiple times during PDF rendering.
368+
return
369+
}
370+
lastPageFinishedUrl = url
371+
361372
val resolvedUrl = when {
362373
url == null -> null
363374
url.startsWith(PDF_VIEWER_URL_PREFIX) && originalUrl != null -> originalUrl

0 commit comments

Comments
 (0)