From aa56f9658595fd3d4c3757485860f7bd0d905fc0 Mon Sep 17 00:00:00 2001 From: eight Date: Sat, 29 Dec 2018 10:55:52 +0800 Subject: [PATCH] Fix: catch syntax error (#627) --- content/apply.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/content/apply.js b/content/apply.js index bbb6a338..24b99830 100644 --- a/content/apply.js +++ b/content/apply.js @@ -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);