OLD | NEW |
1 <h1>Native Messaging</h1> | 1 <h1>Native Messaging</h1> |
2 <p> | 2 <p> |
3 Extensions and apps can exchange messages with native applications using an API | 3 Extensions and apps can exchange messages with native applications using an API |
4 that is similar to the other <a href="messaging">message passing APIs</a>. | 4 that is similar to the other <a href="messaging">message passing APIs</a>. |
5 Native applications that support this feature must register a | 5 Native applications that support this feature must register a |
6 <em>native messaging host</em> that knows how to communicate with the extension. | 6 <em>native messaging host</em> that knows how to communicate with the extension. |
7 Chrome starts the host in a separate process and communicates with it using | 7 Chrome starts the host in a separate process and communicates with it using |
8 standard input and standard output streams. | 8 standard input and standard output streams. |
9 | 9 |
10 <h2 id="native-messaging-host">Native messaging host</h2> | 10 <h2 id="native-messaging-host">Native messaging host</h2> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 Chrome starts each native messaging host in a separate process and communicates | 122 Chrome starts each native messaging host in a separate process and communicates |
123 with it using standard input (<code>stdin</code>) and standard output | 123 with it using standard input (<code>stdin</code>) and standard output |
124 (<code>stdout</code>). The same format is used to send messages in both | 124 (<code>stdout</code>). The same format is used to send messages in both |
125 directions: each message is serialized using JSON, UTF-8 encoded | 125 directions: each message is serialized using JSON, UTF-8 encoded |
126 and is preceded with 32-bit message length in native byte order. | 126 and is preceded with 32-bit message length in native byte order. |
127 The maximum size of a single message from the native messaging host is 1 MB, | 127 The maximum size of a single message from the native messaging host is 1 MB, |
128 mainly to protect Chrome from misbehaving native applications. The maximum | 128 mainly to protect Chrome from misbehaving native applications. The maximum |
129 size of the message sent to the native messaging host is 4 GB. | 129 size of the message sent to the native messaging host is 4 GB. |
130 | 130 |
131 <p> | 131 <p> |
| 132 The first argument to the native messaging host is the origin of the caller, |
| 133 usually <code>chrome-extension://[ID of whitelisted extension]</code>. |
| 134 This allows native messaging hosts to identify the source of the message when |
| 135 multiple extensions are specified in the <code>allowed_origins</code> key in the |
| 136 <a href="#native-messaging-host-manifest">native messaging host manifest</a>. |
| 137 <br> |
| 138 <b><em>Warning</em></b>: In Windows, in Chrome 54 and earlier, the origin was |
| 139 passed as the second parameter instead of the first parameter. |
| 140 |
| 141 <p> |
132 When a messaging port is created using $(ref:runtime.connectNative) Chrome | 142 When a messaging port is created using $(ref:runtime.connectNative) Chrome |
133 starts native messaging host process and keeps it running until the port is | 143 starts native messaging host process and keeps it running until the port is |
134 destroyed. On the other hand, when a message is sent using | 144 destroyed. On the other hand, when a message is sent using |
135 $(ref:runtime.sendNativeMessage), without creating a messaging port, Chrome star
ts | 145 $(ref:runtime.sendNativeMessage), without creating a messaging port, Chrome star
ts |
136 a new native messaging host process for each message. In that case the first | 146 a new native messaging host process for each message. In that case the first |
137 message generated by the host process is handled as a response to the original | 147 message generated by the host process is handled as a response to the original |
138 request, i.e. Chrome will pass it to the response callback specified when | 148 request, i.e. Chrome will pass it to the response callback specified when |
139 $(ref:runtime.sendNativeMessage) is called. All other messages generated by the | 149 $(ref:runtime.sendNativeMessage) is called. All other messages generated by the |
140 native messaging host in that case are ignored. | 150 native messaging host in that case are ignored. |
141 | 151 |
142 <p> | 152 <p> |
143 On Windows, the native messaging host gets passed a command line argument with | 153 On Windows, the native messaging host is also passed a command line argument wit
h |
144 a handle to the calling chrome native window: <code>--parent-window=<decimal | 154 a handle to the calling chrome native window: <code>--parent-window=<decimal |
145 handle value></code>. This lets the native messaging host create native UI | 155 handle value></code>. This lets the native messaging host create native UI |
146 windows that are correctly focused. | 156 windows that are correctly focused. |
147 | 157 |
148 <h2 id="native-messaging-client">Connecting to a native application</h2> | 158 <h2 id="native-messaging-client">Connecting to a native application</h2> |
149 <p> | 159 <p> |
150 Sending and receiving messages to and from a native application is very similar | 160 Sending and receiving messages to and from a native application is very similar |
151 to cross-extension messaging. The main difference is that | 161 to cross-extension messaging. The main difference is that |
152 $(ref:runtime.connectNative) is used instead of $(ref:runtime.connect), | 162 $(ref:runtime.connectNative) is used instead of $(ref:runtime.connect), |
153 and $(ref:runtime.sendNativeMessage) is used instead of $(ref:runtime.sendMessag
e). | 163 and $(ref:runtime.sendNativeMessage) is used instead of $(ref:runtime.sendMessag
e). |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 and | 286 and |
277 <a href="https://developer.chrome.com/extensions/examples/api/nativeMessaging/ho
st.zip">sample host</a>. | 287 <a href="https://developer.chrome.com/extensions/examples/api/nativeMessaging/ho
st.zip">sample host</a>. |
278 | 288 |
279 Run <code>install_host.bat</code> (Windows) or | 289 Run <code>install_host.bat</code> (Windows) or |
280 <code>install_host.sh</code> (Linux / OS X) to install the native messaging | 290 <code>install_host.sh</code> (Linux / OS X) to install the native messaging |
281 host. | 291 host. |
282 Then <a href="getstarted#unpacked">load the app</a> and interact with the app. | 292 Then <a href="getstarted#unpacked">load the app</a> and interact with the app. |
283 Run <code>uninstall_host.bat</code> or <code>uninstall_host.sh</code> to | 293 Run <code>uninstall_host.bat</code> or <code>uninstall_host.sh</code> to |
284 unregister the native messaging host when you are done. | 294 unregister the native messaging host when you are done. |
285 | 295 |
OLD | NEW |