Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/src/main/res/raw/webviewcompat_test_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const supportedMessages = ["ContextMenuOpened", "PageStarted"];

const delay = $DELAY$;
const postInitialPing = $POST_INITIAL_PING$;
const replyToNativeMessages = $REPLY_TO_NATIVE_MESSAGES$;

const webViewCompatPingMessage = 'Ping:' + window.location.href + ' ' + delay + 'ms'


if (postInitialPing) {
if (delay > 0) {
setTimeout(() => {
webViewCompatTestObj.postMessage(webViewCompatPingMessage)
}, delay)
} else {
webViewCompatTestObj.postMessage(webViewCompatPingMessage)
}
}


webViewCompatTestObj.onmessage = function(event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it matter if native haven't defined a web message listener? e.g., will webViewCompatTestObj not being defined cause an issue?

Copy link
Contributor Author

@CrisBarreiro CrisBarreiro Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have some sort of message listener for all testing scenarios, so it shouldn't be a concern. Also, we don't have a proper way to know if a listener is defined on the native side. In any case, AFAIK, if no listener is defined, we'll see a log in Chrome console, but otherwise, the script would work as normal, with messages being, of course, ignored by native

console.log("webViewCompatTestObj received", event.data)
if (replyToNativeMessages && supportedMessages.includes(event.data)) {
webViewCompatTestObj.postMessage(event.data + " from webViewCompatTestObj")
}
}

window.onmessage = function(event) {
console.log("window received", event.data)
if (replyToNativeMessages && supportedMessages.includes(event.data)) {
webViewCompatTestObj.postMessage(event.data + " from window")
}
}
Loading