[FIX] playground: remove error handler after 100ms

The error handler is intended to only detect errors at 'startup',  not
in the normal course of operation.
This commit is contained in:
Géry Debongnie
2019-04-24 16:17:27 +02:00
parent b8eaa649c6
commit 866e12dc27
+8 -4
View File
@@ -143,7 +143,7 @@ class App extends owl.Component {
const iframe = document.createElement("iframe"); const iframe = document.createElement("iframe");
iframe.onload = () => { iframe.onload = () => {
const doc = iframe.contentWindow.document; const doc = iframe.contentDocument;
// inject js // inject js
const owlScript = doc.createElement("script"); const owlScript = doc.createElement("script");
owlScript.type = "text/javascript"; owlScript.type = "text/javascript";
@@ -155,9 +155,13 @@ class App extends owl.Component {
this.state.js this.state.js
}`; }`;
script.innerHTML = content; script.innerHTML = content;
iframe.contentWindow.addEventListener("error", e => const errorHandler = e => this.displayError(e.message);
this.displayError(e.message) iframe.contentWindow.addEventListener("error", errorHandler);
); setTimeout(function() {
if (iframe.contentWindow) {
iframe.contentWindow.removeEventListener("error", errorHandler);
}
}, 100);
doc.body.appendChild(script); doc.body.appendChild(script);
}); });
doc.head.appendChild(owlScript); doc.head.appendChild(owlScript);