Skip to content

Commit c06a4fc

Browse files
authored
Add base script for de-risking new WebViewCompat APIs (#7034)
Task/Issue URL: https://app.asana.com/1/137249556945/task/1211755269770776?focus=true ### Description Create base script to be used as a test bed. Script contains placeholder so it can be configured as needed from native ### Steps to test this PR n/a ### UI changes n/a
1 parent c1d9f57 commit c06a4fc

File tree

1 file changed

+33
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)