Having upgraded to Electron 7.0, I've noticed this deprecation message:
(node:8308) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
The code in question is:
await new Promise((resolve, reject) => {
electron.protocol.registerBufferProtocol(MY_PROTOCOL,
(request, callback) => {
const uri = request.url;
if (uri) {
callback({ mimeType: 'text/plain', data: Buffer.from(uri) });
}
else {
callback({ error: -324 }); // EMPTY_RESPONSE
}
},
error => error? reject(error): resolve()
);
});
What's the proper way of calling registerBufferProtocol
now, as of Electron 7?
It took me some noticeable time to figure out how to call registerBufferProtocol
properly with Electron 7.0, so sharing this with the community and my future self.
According to Electron's Breaking changes document, registerBufferProtocol
is now synchronous, so calling it has actually got simpler:
electron.protocol.registerBufferProtocol(MY_PROTOCOL,
(request, callback) => {
const uri = request.url;
if (uri) {
callback({ mimeType: 'text/plain', data: Buffer.from(uri) });
}
else {
callback({ error: -324 }); // EMPTY_RESPONSE
}
});
The confusing (to me) part of the warning was that the callback
is actually not the callback
arg to the handler
, but rather is the last completion
arg passed to the protocol.registerBufferProtocol
API itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With