Skip to content

Uncaught ReferenceError: ipcApi is not defined #288

Description

@kilburn

We've been using electron-pdf for a while. Recently we noticed that PDF generation seemed to be slower than it used to. Inspecting the logs we saw that electron-pdf was logging some error:

(node:17343) UnhandledPromiseRejectionWarning: Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
    at WebFrame../lib/renderer/api/web-frame.ts.WebFrame.<computed> [as executeJavaScript] (electron/js2c/renderer_init.js:1806:33)
    at electron/js2c/renderer_init.js:3066:43
    at electron/js2c/renderer_init.js:2695:40
    at new Promise (<anonymous>)
    at EventEmitter.<anonymous> (electron/js2c/renderer_init.js:2695:9)
    at EventEmitter.emit (events.js:203:13)
    at Object.onMessage (electron/js2c/renderer_init.js:2469:16)
(node:17343) UnhandledPromiseRejectionWarning: Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
    at WebFrame../lib/renderer/api/web-frame.ts.WebFrame.<computed> [as executeJavaScript] (electron/js2c/renderer_init.js:1806:33)
    at electron/js2c/renderer_init.js:3066:43
    at electron/js2c/renderer_init.js:2695:40
    at new Promise (<anonymous>)
    at EventEmitter.<anonymous> (electron/js2c/renderer_init.js:2695:9)
    at EventEmitter.emit (events.js:203:13)
    at Object.onMessage (electron/js2c/renderer_init.js:2469:16)

This didn't seem a problem in our code but something in electron or electron-pdf being wrong. After enabling electron's logging (passing --enable-logging to the command), we got the actual javascript error:

[17343:0523/083655.168148:INFO:CONSOLE(3)] "Uncaught ReferenceError: ipcApi is not defined", source: https://127.0.0.1/redacted

This pointed us to the real issue:

  • When electron-pdf prepares a job, it injects the lib/preload.js file, which is supposed to provide an ipcApi object with some methods that call node's internal APIs.
  • For some reason this stopped working at some point (this is the issue)
  • As a result, the view-ready event notification cannot be bridged back to electron-pdf and our PDFs are generated only after the timeout. That's why it got slower for us.

We have been able to reproduce this in several systems, including:

  • Ubuntu 18.04, node v10.24.0, electron 7.3.3, electron-pdf 7.0.1
  • Debian 10, node v10.24.0, electron 7.3.3, electron-pdf 7.0.1
  • Debian 10, node v12.16.3, electron 12.0.9, electron-pdf 10.0.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions