fraserxu / electron-pdf

📄 A command line tool to generate PDF from URL, HTML or Markdown files.
MIT License
1.24k stars 136 forks source link

Electron's `contextIsolation` option is enabled by default from electron 12 #289

Closed kilburn closed 2 years ago

kilburn commented 3 years ago

As noted in the docs, the contextIsolation option is enabled by default from electron 12 on: https://www.electronjs.org/docs/tutorial/context-isolation#how-do-i-enable-it

This breaks the current implementation of electron-pdf because the ipcApi object that gets defined in the preload.js is not accessible from within the webpage's javascript itself. To handle the ready event, we inject a listener in exportJob.js#_executeJSListener that tries to use that object but fails because it is not defined in the page's context.

This can be solved in two ways:

  1. Eplicitly disable contextIsolation when setting up the job in setupJob.js
  2. Use the contextBridge api to expose ipcApi to the website's context.

I will work on a PR that implements solution 2.

codecounselor commented 2 years ago

Fixed in v15.0.0