Skip to content
This repository was archived by the owner on Sep 25, 2021. It is now read-only.

Commit 9bd156c

Browse files
committed
Fix webkit user script messages not being called when web view is hidden (#93)
* Call postMessage immediately when document is not visible * Use document.hidden instead of comparing visibilityState visibilityState may be options other than “hidden” that are considered hidden, like prerender.
1 parent f700bca commit 9bd156c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Turbolinks/WebView.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,15 @@
9797
},
9898

9999
postMessageAfterNextRepaint: function(name, data) {
100-
var postMessage = this.postMessage.bind(this, name, data)
101-
requestAnimationFrame(function() {
102-
requestAnimationFrame(postMessage)
103-
})
100+
// Post immediately if document is hidden or message may be queued by call to rAF
101+
if (document.hidden) {
102+
this.postMessage(name, data);
103+
} else {
104+
var postMessage = this.postMessage.bind(this, name, data)
105+
requestAnimationFrame(function() {
106+
requestAnimationFrame(postMessage)
107+
})
108+
}
104109
}
105110
}
106111

0 commit comments

Comments
 (0)