Protocol object is missing methods like registerBufferProtocol


#1

From my main.js, I’m trying to register a protocol handler with the electron.protocol object. I am finding that the protocol object is missing all of the register methods such as registerBufferProtocol so all of the sample code in the docs fail for me as the methods on protocol object are undefined.

In main.js:

const electron = require(‘electron’)
const protocol = electron.protocol;
console.log(protocol);

This yields

{ registerStandardSchemes: [Function],
getStandardSchemes: [Function] }

Where are all of the other functions like registerBufferProtocol?

Thanks
Don


#2

I haven’t used any of those methods in my own projects, but I would say that if you’re seeing something clearly divergent from the documentation, you should screenshot the results and drop an issue in the Electron repo.


#3

from https://github.com/electron/electron/blob/master/docs/api/protocol.md#protocol

Note: All methods unless specified can only be used after the ready event of the app module gets emitted.

maybe you can try after app.on(‘ready’) get called?


#4

Thanks for the suggestions. I get the same thing in after the app ready event:

app.on(‘ready’, function () {
console.log(electron.protocol);
createWindow();
})

outputs:

{ registerStandardSchemes: [Function],
getStandardSchemes: [Function] }


#5

right, the console.log will return same thing ( i have no idea on this as i did not dig in the detail), however, you should be able to call those functions now. previously you will get undefined instead.


#6

Wow… you are correct. I could call registerBufferProtocol in the app ready handler. I’m baffled as to why console.log(electron.protocol) in the same place doesn’t have the function on it during its output. Maybe the object being logged is just thrown on a queue and the output of log happens later? Once the app ready handler exits maybe the methods are torn off the protocol object?
Anyway… thanks for help. I am unblocked.