Skip to content

Commit 6f2c5e3

Browse files
committed
Add base script for de-risking new WebViewCompat APIs
1 parent ba87b34 commit 6f2c5e3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
let supportedMessages = ["ContextMenuOpened", "PageStarted"];
2+
3+
const delay = $DELAY$;
4+
const postInitialPing = $POST_INITIAL_PING$;
5+
const replyToNativeMessages = $REPLY_TO_NATIVE_MESSAGES$;
6+
7+
const pingMessage = 'Ping:' + window.location.href + ' ' + delay + 'ms'
8+
9+
10+
if (postInitialPing) {
11+
setTimeout(() => {
12+
webViewCompatTestObj.postMessage(pingMessage)
13+
}, delay)
14+
}
15+
16+
17+
webViewCompatTestObj.onmessage = function(event) {
18+
console.log("webViewCompatTestObj received", event.data)
19+
if (replyToNativeMessages && supportedMessages.includes(event.data)) {
20+
webViewCompatTestObj.postMessage(event.data + " from webViewCompatTestObj")
21+
}
22+
}
23+
24+
window.onmessage = function(event) {
25+
console.log("window received", event.data)
26+
if (replyToNativeMessages && supportedMessages.includes(event.data)) {
27+
webViewCompatTestObj.postMessage(event.data + " from window")
28+
}
29+
}

0 commit comments

Comments
 (0)