From 4fd57a33c95fb19adbf89230ef26d1c428cdd574 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Tue, 25 Aug 2020 20:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20beforeExec=20hook=20(#54)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 1 + src/index.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index aa0f95c..15cfc97 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,6 +25,7 @@ type ExecScriptsOpts = Pick & { strictGlobal?: boolean; success?: CallableFunction; error?: CallableFunction; + beforeExec?: CallableFunction; } export type Entry = string | { styles?: string[], scripts?: string[], html?: string }; diff --git a/src/index.js b/src/index.js index 1cf102a..3f7a6b8 100644 --- a/src/index.js +++ b/src/index.js @@ -136,13 +136,17 @@ const supportsUserTiming = export function execScripts(entry, scripts, proxy = window, opts = {}) { const { fetch = defaultFetch, strictGlobal = false, success, error = () => { + }, beforeExec = () => { }, } = opts; return getExternalScripts(scripts, fetch, error) .then(scriptsText => { - const geval = eval; + const geval = (code) => { + beforeExec(); + (0, eval)(code); + }; function exec(scriptSrc, inlineScript, resolve) {