Fix: catch syntax error (#627)
This commit is contained in:
parent
0c8e69fb9d
commit
aa56f96585
|
@ -130,15 +130,21 @@ const APPLY = (() => {
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
const {resolve, promise} = deferred();
|
const {resolve, promise} = deferred();
|
||||||
script.src = src;
|
script.src = src;
|
||||||
script.onerror = () => resolve(false);
|
script.onerror = resolveFalse;
|
||||||
|
window.addEventListener('error', resolveFalse);
|
||||||
window.addEventListener(EVENT_NAME, handleInit);
|
window.addEventListener(EVENT_NAME, handleInit);
|
||||||
(document.head || document.documentElement).appendChild(script);
|
(document.head || document.documentElement).appendChild(script);
|
||||||
return promise.then(result => {
|
return promise.then(result => {
|
||||||
script.remove();
|
script.remove();
|
||||||
window.removeEventListener(EVENT_NAME, handleInit);
|
window.removeEventListener(EVENT_NAME, handleInit);
|
||||||
|
window.removeEventListener('error', resolveFalse);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function resolveFalse() {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
function handleInit(e) {
|
function handleInit(e) {
|
||||||
if (e.detail.method === 'init') {
|
if (e.detail.method === 'init') {
|
||||||
resolve(e.detail.available);
|
resolve(e.detail.available);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user