Is it possible to call CGWindowListCreateImage from Electron on Mac?

Discussion in 'macOS Virtual Machine' started by MelvinaN, Dec 15, 2020.

  1. MelvinaN

    MelvinaN Junior Member

    Messages:
    17
    I'm looking for a reliable and performant way to get a screenshot of the entire screen in Electron on Mac. I've tried to use navigator.mediaDevices.getUserMedia (slow and lossy compression) and to spawn "screencapture" process (even slower: 400ms-2s depending on the machine, I blame disk IO). I also tried to compile a native app that calls CGWindowListCreateImage, it took an impressive 17ms to get the job done. If I could somehow call the Cocoa api from Electron and then transform the result to js ImageData that will likely solve my problem.

    I tried Node → Cocoa bridges (NodObjC and objc), but both projects seem abandoned and incompatible with the latest version of Node.

    I tried to create a simple Node addon with the node-gyp but got stuck because all node-gyp documentation revolves around C++ (you can't call Cocoa api from C++, can you?).

    Am I digging in the right direction?
     

Share This Page