yhirose/react-typescript-electron-sample-with-create-react-app-and-electron-builder

preload issue

zhdxmw opened this issue · 1 comments

in the mian.ts

function createWindow() {
	win = new BrowserWindow({
               ...
		webPreferences: {
			nodeIntegration: true,
			webviewTag: true,
			enableRemoteModule: true,
			contextIsolation: true,
			plugins: true,
			webSecurity: false,
			autoplayPolicy: 'no-user-gesture-required',
			preload: path.join(__dirname, './preload.js'),
			// preload: process.cwd() + path.join(__dirname, './preload.ts'),
		},
	})

// preload.ts
console.log('electron preload')
window.ipc = ipc
window.hello = 'hello'
`
image

code executed but not work

webview preload also not work

<webview
		src="http://localhost:8888/dist/webview.html"
		style={{ width: '600px', height: '600px' }}
		// preload={`${path.join(__dirname, '/../../electron/preload.js')}`}
		preload={`file://${path.join(__dirname, '../../electron/preload.js')}`}
	/>

​ case 1: not start with ' file '
​ error : Only "file:" protocol is supported in "preload" attribute.

case 2: with ' file ':

webview deveTools :
image

thanks

@zhdxmw, thanks for the report, but using preload feature is out of scope of this boiler plate sample.
Please see https://www.electronjs.org/docs/api/sandbox-option#preload to implement it properly.
Hope it helps.