{"id":26481924,"url":"https://github.com/electron-utils/electron-protocols","last_synced_at":"2026-03-09T13:01:56.785Z","repository":{"id":57221854,"uuid":"79765230","full_name":"electron-utils/electron-protocols","owner":"electron-utils","description":"Manage file protocols in Electron","archived":false,"fork":false,"pushed_at":"2017-04-19T04:04:26.000Z","size":92,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T10:06:29.310Z","etag":null,"topics":["electron","filesystem-path","protocol"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/electron-utils.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-23T03:11:16.000Z","updated_at":"2022-03-29T04:37:58.000Z","dependencies_parsed_at":"2022-08-29T01:51:06.696Z","dependency_job_id":null,"html_url":"https://github.com/electron-utils/electron-protocols","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electron-utils%2Felectron-protocols","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electron-utils%2Felectron-protocols/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electron-utils%2Felectron-protocols/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electron-utils%2Felectron-protocols/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/electron-utils","download_url":"https://codeload.github.com/electron-utils/electron-protocols/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244545289,"owners_count":20469829,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","filesystem-path","protocol"],"created_at":"2025-03-20T03:36:17.346Z","updated_at":"2026-03-09T13:01:51.674Z","avatar_url":"https://github.com/electron-utils.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-protocols\n\n[![Linux Build Status](https://travis-ci.org/electron-utils/electron-protocols.svg?branch=master)](https://travis-ci.org/electron-utils/electron-protocols)\n[![Windows Build status](https://ci.appveyor.com/api/projects/status/rb2koei7jtsgnfyh?svg=true)](https://ci.appveyor.com/project/jwu/electron-protocols)\n[![Dependency Status](https://david-dm.org/electron-utils/electron-protocols.svg)](https://david-dm.org/electron-utils/electron-protocols)\n[![devDependency Status](https://david-dm.org/electron-utils/electron-protocols/dev-status.svg)](https://david-dm.org/electron-utils/electron-protocols#info=devDependencies)\n\nManage file protocols in Electron\n\n## Install\n\n```bash\nnpm install --save electron-protocols\n```\n\nRun the example:\n\n```\nnpm start example\n```\n\n## Usage\n\nFirst register your protocol in main process before `app.on('ready')`:\n\n**main process**\n\n```javascript\nconst protocols = require('electron-protocols');\nprotocols.register('app', protocols.basepath(app.getAppPath()));\n```\n\nThen you can use `protocols.path` to map your protocol to a file path:\n\n**renderer/main process**\n\n```javascript\nconst protocols = require('electron-protocols');\n\n// return the module in ${app.getAppPath()}/my/module.js\nconst myModule = require(protocols.path('app://my/module.js'));\n```\n\nAlso, you are free to use protocol in html in renderer process:\n\n```html\n  \u003cimg src=\"app://my/image.png\" /\u003e\n  \u003cscript src=\"app://my/script.js\" /\u003e\n```\n\n## FAQ\n\n### What is the benefit to register again in renderer process?\n\nIt will speed up the search of `protocols.path` by skip calling the remote (ipc-sync) functions.\n\n## API\n\n### Methods\n\n### protocols.register(protocol, fn)\n\n  - `protocol` string\n  - `fn` function\n\nRegister a protocol so that {@link Editor.url} can use it to convert an url to the filesystem path.\nThe `fn` accept an url Object via [url.parse](https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost)\n\nExample:\n\n```javascript\nconst {app} = require('electron');\nconst protocols = require('electron-protocols');\nconst path = require('path');\n\nprotocols.register('app', uri =\u003e {\n  let base = app.getAppPath();\n  if ( uri.pathname ) {\n    return path.join( base, uri.host, uri.pathname );\n  }\n  return path.join( base, uri.host );\n});\n```\n\n### protocols.path(url)\n\n  - `url` string\n\nConvert a url by its protocol to a filesystem path. This function is useful when you try to get\nsome internal file. You can use `protocols.register` to register and map your filesystem path to url.\n\nExample:\n\n```javascript\n// it will return \"{your-app-path}/foobar/foobar.js\"\nprotocols.path('app://foobar/foobar.js');\n```\n\n### protocols.basepath(base)\n\n  - `base` string\n\nA function help you register protocol by `base` path you provide.\n\nExample:\n\n```javascript\nprotocols.register('app', protocols.basepath(app.getAppPath()));\n```\n\n## License\n\nMIT © 2017 Johnny Wu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectron-utils%2Felectron-protocols","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felectron-utils%2Felectron-protocols","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectron-utils%2Felectron-protocols/lists"}