Skip to content

Commit

Permalink
docs: improve registerFileProtocol example (#35599)
Browse files Browse the repository at this point in the history
docs: improve registerFileProtocol example (#35580)

* improve registerFileProtocol example

* link ProtocolResponse

* kick lint

Co-authored-by: Kishan Bagaria <hi@kishan.info>
  • Loading branch information
trop[bot] and KishanBagaria committed Sep 13, 2022
1 parent 672464d commit fad97e0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/api/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ An example of implementing a protocol that has the same effect as the
```javascript
const { app, protocol } = require('electron')
const path = require('path')
const url = require('url')

app.whenReady().then(() => {
protocol.registerFileProtocol('atom', (request, callback) => {
const url = request.url.substr(7)
callback({ path: path.normalize(`${__dirname}/${url}`) })
const filePath = url.fileURLToPath('file://' + request.url.slice('atom://'.length))
callback(filePath)
})
})
```
Expand Down Expand Up @@ -175,7 +176,7 @@ property.
* `handler` Function
* `request` [ProtocolRequest](structures/protocol-request.md)
* `callback` Function
* `response` ProtocolResponse
* `response` [ProtocolResponse](structures/protocol-response.md)

Returns `boolean` - Whether the protocol was successfully registered

Expand Down

0 comments on commit fad97e0

Please sign in to comment.