Fix: catch syntax error (#627)

This commit is contained in:
eight 2018-12-29 10:55:52 +08:00 committed by Rob Garrison
parent 0c8e69fb9d
commit aa56f96585

View File

@ -130,15 +130,21 @@ const APPLY = (() => {
const script = document.createElement('script');
const {resolve, promise} = deferred();
script.src = src;
script.onerror = () => resolve(false);
script.onerror = resolveFalse;
window.addEventListener('error', resolveFalse);
window.addEventListener(EVENT_NAME, handleInit);
(document.head || document.documentElement).appendChild(script);
return promise.then(result => {
script.remove();
window.removeEventListener(EVENT_NAME, handleInit);
window.removeEventListener('error', resolveFalse);
return result;
});
function resolveFalse() {
resolve(false);
}
function handleInit(e) {
if (e.detail.method === 'init') {
resolve(e.detail.available);