From e0858a12fa0aabb8d9f19e6b5c8eca809b8fc48c Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Sat, 8 Apr 2023 22:59:37 +0100 Subject: [PATCH] main: do not error out with CJS --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 5510791..581d22a 100644 --- a/src/index.js +++ b/src/index.js @@ -238,7 +238,11 @@ const startBrowser = async (url, parentDir, { allowHTTP = false, allowNavigation }; // get parent directory of where function was called from -const getParentDir = () => dirname(fileURLToPath((new Error()).stack.split('\n')[3].slice(7).trim().split(':').slice(0, -2).join(':'))); +const getParentDir = () => { + let place = (new Error()).stack.split('\n')[3].slice(7).trim().split(':').slice(0, -2).join(':'); + if (place.startsWith('file://')) place = fileURLToPath(place); + return dirname(place); +}; const checkForDangerousOptions = ({ allowHTTP, allowNavigation }) => { if (allowHTTP === true) dangerousAPI('Gluon.open', 'allowHTTP', 'true');