From 005f903852f2292cf11b838648550a772f77b245 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 2 Feb 2023 00:04:17 +0000 Subject: [PATCH] fix: nodeIntegrationInWorker in AudioWorklets Co-authored-by: Jeremy Rose --- lib/worker/init.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/worker/init.ts b/lib/worker/init.ts index 6a5b11495a8f4..5c537892caa35 100644 --- a/lib/worker/init.ts +++ b/lib/worker/init.ts @@ -21,8 +21,9 @@ global.module = new Module('electron/js2c/worker_init'); global.require = makeRequireFunction(global.module); // Set the __filename to the path of html file if it is file: protocol. -if (self.location.protocol === 'file:') { - const pathname = process.platform === 'win32' && self.location.pathname[0] === '/' ? self.location.pathname.substr(1) : self.location.pathname; +// NB. 'self' isn't defined in an AudioWorklet. +if (typeof self !== 'undefined' && self.location.protocol === 'file:') { + const pathname = process.platform === 'win32' && self?.location.pathname[0] === '/' ? self?.location.pathname.substr(1) : self?.location.pathname; global.__filename = path.normalize(decodeURIComponent(pathname)); global.__dirname = path.dirname(global.__filename);