From 545ba87af88dd8559154cb1dfde9d84a2ce96de5 Mon Sep 17 00:00:00 2001 From: David Alberts Date: Tue, 27 Oct 2026 10:00:20 -0600 Subject: [PATCH] Expose webUtils.getPathForFile as window.Native.getPathForFile for dropped files Electron 32 removed File.path in favour of webUtils.getPathForFile(), which is only available in a preload script. With contextIsolation enabled and NativePHP's preload always set, apps had no way to get the path of a file dropped into a window or picked with . --- resources/electron/electron-plugin/dist/preload/index.mjs | 3 ++- resources/electron/electron-plugin/src/preload/index.mts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/resources/electron/electron-plugin/dist/preload/index.mjs b/resources/electron/electron-plugin/dist/preload/index.mjs index c645a8f5..42063a71 100644 --- a/resources/electron/electron-plugin/dist/preload/index.mjs +++ b/resources/electron/electron-plugin/dist/preload/index.mjs @@ -1,5 +1,5 @@ import remote from '@electron/remote'; -import { contextBridge, ipcRenderer } from 'electron'; +import { contextBridge, ipcRenderer, webUtils } from 'electron'; const Native = { on: (event, callback) => { ipcRenderer.on('native-event', (_, data) => { @@ -14,6 +14,7 @@ const Native = { const menu = remote.Menu.buildFromTemplate(template); menu.popup({ window: remote.getCurrentWindow() }); }, + getPathForFile: (file) => webUtils.getPathForFile(file), }; contextBridge.exposeInMainWorld('Native', Native); ipcRenderer.on('log', (event, { level, message, context }) => { diff --git a/resources/electron/electron-plugin/src/preload/index.mts b/resources/electron/electron-plugin/src/preload/index.mts index 71d787ed..b8eb9382 100644 --- a/resources/electron/electron-plugin/src/preload/index.mts +++ b/resources/electron/electron-plugin/src/preload/index.mts @@ -1,5 +1,5 @@ import remote from '@electron/remote'; -import { contextBridge, ipcRenderer } from 'electron'; +import { contextBridge, ipcRenderer, webUtils } from 'electron'; // ------------------------------------------------------------------- // The Native helper @@ -20,6 +20,10 @@ const Native = { const menu = remote.Menu.buildFromTemplate(template); menu.popup({ window: remote.getCurrentWindow() }); }, + // The file system path of a File from a drop or an . + // Electron 32 removed File.path and webUtils is only available in a preload. + // Returns an empty string when the File isn't backed by a file on disk. + getPathForFile: (file: File): string => webUtils.getPathForFile(file), }; contextBridge.exposeInMainWorld('Native', Native);