{"id":15021990,"url":"https://github.com/simov/native-messaging","last_synced_at":"2025-06-18T18:33:58.908Z","repository":{"id":32988620,"uuid":"148887964","full_name":"simov/native-messaging","owner":"simov","description":"Native Messaging Host Protocol for Browser Extensions","archived":false,"fork":false,"pushed_at":"2023-06-03T23:53:58.000Z","size":6,"stargazers_count":50,"open_issues_count":5,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-23T01:18:22.865Z","etag":null,"topics":["browser-extension","chrome","chrome-extension","firefox","firefox-addon","firefox-extension","javascript","native-messaging","nodejs"],"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/simov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-15T09:26:09.000Z","updated_at":"2025-04-09T00:06:50.000Z","dependencies_parsed_at":"2024-06-21T07:12:41.442Z","dependency_job_id":"f35bd4c4-ed7a-4c1f-82ee-f4c1bf9b1eff","html_url":"https://github.com/simov/native-messaging","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/simov/native-messaging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fnative-messaging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fnative-messaging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fnative-messaging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fnative-messaging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simov","download_url":"https://codeload.github.com/simov/native-messaging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simov%2Fnative-messaging/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260609419,"owners_count":23035941,"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":["browser-extension","chrome","chrome-extension","firefox","firefox-addon","firefox-extension","javascript","native-messaging","nodejs"],"created_at":"2024-09-24T19:57:18.356Z","updated_at":"2025-06-18T18:33:53.890Z","avatar_url":"https://github.com/simov.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\n# native-messaging\n\n[![npm-version]][npm]\n\n\u003e Native Messaging Host Protocol for Browser Extensions ([Chrome][native-messaging], [Firefox][native-messaging-ff])\n\n# API\n\n```js\n#!/home/s/.nvm/versions/node/v8.11.2/bin/node\n\n// Might be good to use an explicit path to node on the shebang line\n// in case it isn't in PATH when launched by Chrome/Firefox\n\nvar sendMessage = require('native-messaging')(handleMessage)\n\nfunction handleMessage (req) {\n  if (req.message === 'ping') {\n    sendMessage({message: 'pong', body: 'hello from nodejs app'})\n  }\n}\n```\n\n# Tips\n\n- `chrome.runtime.connectNative` returns a `Port` that can be used to establish persistent connection between the browser and the native app\n- the Port's `disconnect` method can be used to disconnect from the native app\n- the native app can use the OS's machinery to kill its own process at any time\n- `chrome.runtime.sendNativeMessage` can be used to send single message to the native app, useful with _non persistent background pages_\n- single native app can communicate with multiple browser extensions\n- single browser extension can communicate with multiple native apps\n\n# Things to look for\n\n1. Add `nativeMessaging` permission to the `manifest.json` file of your extension\n2. Load the extension to get its ID generated\n3. Put the `native.messaging.example.json` in `~/.config/google-chrome/NativeMessagingHosts/` or `~/.mozilla/native-messaging-hosts/`\n  - The name of the file should be identical to the `name` field specified in that file\n  - Only dots `.` are allowed as delimiters in the file name\n  - The `path` key should be absolute path to your nodejs script `example.js`\n  - Chrome - the `allowed_origins` key should contain the extension's ID loaded in step 2\n  - Firefox - the `allowed_extensions` key should contain the extension's ID specified in its `manifest.json` file\n4. Make sure that `example.js` is executable `chmod 755`\n5. Make sure nodejs is reachable from the shebang line in `example.js`\n6. Use the `name` specified in `native.messaging.example.json` to connect to the native app from the extension's background page `background.js`\n\n\u003e Note that the install location for the `native.messaging.example.json` differs for each OS and browser. In case you plan to support multiple platforms, it's best to use install script. Here is an example of [such script][install].\n\n# References\n\nTopic                            | Chrome                      | Firefox\n:--                              | :---                        | :---\nNative Messaging Host Protocol   | [link][native-messaging]    | [link][native-messaging-ff]\nchrome.runtime.connectNative     | [link][connect-native]      | [link][connect-native-ff]\nPort                             | [link][port]                | [link][port-ff]\nchrome.runtime.sendNativeMessage | [link][send-native-message] | [link][send-native-message-ff]\nhost.json location               | [link][host-location]       | [link][host-location-ff]\nofficial example                 | [link][example]             | [link][example-ff]\n\n\n  [npm-version]: https://img.shields.io/npm/v/native-messaging.svg?style=flat-square (NPM Package Version)\n  [npm]: https://www.npmjs.com/package/native-messaging\n\n  [native-messaging]: https://developer.chrome.com/extensions/nativeMessaging\n  [connect-native]: https://developer.chrome.com/extensions/runtime#method-connectNative\n  [port]: https://developer.chrome.com/extensions/runtime#type-Port\n  [send-native-message]: https://developer.chrome.com/extensions/runtime#method-sendNativeMessage\n  [host-location]: https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location\n  [example]: https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/nativeMessaging\n\n  [native-messaging-ff]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging\n  [connect-native-ff]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/connectNative\n  [port-ff]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port\n  [send-native-message-ff]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/sendNativeMessage\n  [host-location-ff]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#Manifest_location\n  [example-ff]: https://github.com/mdn/webextensions-examples/tree/master/native-messaging\n\n  [background-pages]: https://developers.chrome.com/extensions/background_pages\n\n  [install]: https://github.com/browserpass/browserpass/blob/master/install.sh\n\n  [example-1]: https://github.com/flashlizi/node-chrome-bridge\n  [example-2]: https://github.com/jdiamond/chrome-native-messaging\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimov%2Fnative-messaging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimov%2Fnative-messaging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimov%2Fnative-messaging/lists"}