File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments