

- #Electron api demo pdf#
- #Electron api demo full#
- #Electron api demo portable#
- #Electron api demo code#
Since our PDF engine doesn’t require low-level OS APIs (as such, it can also be used on the web with our Web PDF SDK), we needed to make sure we made the proper decision for our customers.

When working on our Electron PDF SDK, we evaluated both the native extension and the WebAssembly approach and compared the results. For a quick glimpse of the current stage, consider reading up on optimizing WebAssembly startup time. But improvements in this area are underway, and we’re certain that the startup time will vastly improve over the course of the next few months. This is mainly because the WebAssembly intermediate format must be compiled to the target architecture before it can run natively. The biggest drawback of WebAssembly versus the native extensions approach is that it takes longer to start a WebAssembly module. Since Electron 3.0.0 comes with Chrome 66, we can rely on its WebAssembly engine to run high computational work with maximum performance, even in your Electron app.
#Electron api demo code#
WebAssembly can be used as a compilation target for most native programming languages (C, C++, or even Rust) and allows you to run high-performance code in a browser. If you’ve never heard of WebAssembly, I highly recommend checking out our introductory blog post. Thankfully, there exists an alternative to using native extensions in Electron with none of the drawbacks outlined above: WebAssembly - a portable, binary instruction format supported by all major browsers. This could put your app under increased security risk.
#Electron api demo full#
Native extensions have full access to the OS API. If you’re running into this problem, we suggest you have a look at the fantastic prebuild project. For your Electron app, this means you’ll have to put in additional effort to always compile to all target platforms. Native code always needs to be compiled to the platform it’s used to run on. If you, for example, use a low-level OS API to achieve specific optimizations, there’s a very high probability that this API isn’t present on other platforms.
#Electron api demo portable#
It’s super simple to port native modules for using them inside your Electron app, but compiling to native also has some downsides:Īlthough there are several packages that increase the portability of your C++ code for use within Electron, this code will never be as portable as plain JavaScript. Voilà! We’ve successfully run our own native module in Electron. native-increment').increment ĭocument.querySelector(' #result').innerHTML = increment( 1336) native-increment') ĭocument.querySelector(' #result').innerHTML = increment( 1336) var increment = require('. Such a function would look like the following when written in plain JavaScript:Ĭonst = require('. To demonstrate the use of native modules, we’ll write a simple package that adds one to the number passed in as an argument. We can require the native extension inside our JavaScript code and communicate via the interface we set up. Using native modules is straightforward, as we’ll see in the example below. To compile the code, we make use of node-gyp, a cross-platform command-line tool for compiling native modules using the GYP project. These modules are special npm packages that can contain C/C++ code and will compile to the target architecture upon installation. Native Modules in ElectronĮlectron has first-class support for native Node.js modules (also called native addons). The source code for the following examples is available on GitHub. This article provides a brief overview of the available options. In the past few years, it has been adopted by major companies in the tech industry, including GitHub, Facebook, Microsoft, and Slack.Īlthough Electron comes with access to the entire npm ecosystem, sometimes your application requires the use of native code, either to have direct access to the APIs of your operating system, or to be able to run tasks that require a lot of computing power.įor our Electron PDF library, we evaluated multiple approaches to bringing our high-performance PDF engine to this platform. Electron is a powerful open source framework that allows development of cross-platform desktop GUI applications with JavaScript, HTML, and CSS.
