Created
February 6, 2018 12:15
-
-
Save nagyv/90e2aa47c13f328cd5006eb9c3250379 to your computer and use it in GitHub Desktop.
example html for an RN bug report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<script> | |
// from: https://github.com/facebook/react-native/issues/11594#issuecomment-274689549 | |
function awaitPostMessage() { | |
let isReactNativePostMessageReady = !!window.originalPostMessage; | |
const queue = []; | |
let currentPostMessageFn = function store(message) { | |
if (queue.length > 100) queue.shift(); | |
queue.push(message); | |
}; | |
if (!isReactNativePostMessageReady) { | |
// const originalPostMessage = window.postMessage; | |
Object.defineProperty(window, 'postMessage', { | |
configurable: true, | |
enumerable: true, | |
get() { | |
return currentPostMessageFn; | |
}, | |
set(fn) { | |
currentPostMessageFn = fn; | |
isReactNativePostMessageReady = true; | |
setTimeout(sendQueue, 0); | |
} | |
}); | |
} | |
function sendQueue() { | |
while (queue.length > 0) window.postMessage(queue.shift()); | |
} | |
} | |
awaitPostMessage(); | |
document.addEventListener('message', function(e) { | |
console.log(e.data); | |
document.getElementById('text').innerHTML = 'hello world'; // e.data; | |
}); | |
window.addEventListener('load', function loader() { | |
window.postMessage('loaded', '*') | |
}); | |
</script> | |
<style> | |
body { | |
font-size: 40em; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Hello there</h1> | |
<p>Message text follows:</p> | |
<div id="text"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment