This takes one argument, which is a serializable value (see Data cloning algorithm) representing the message to send. The listener will be passed the value that the other end sent. Listener functions will be called when the other end has sent this port a message. This contains the addListener() and removeListener() functions common to all events for extensions built using WebExtension APIs. Note that in Google Chrome port.error is not supported: instead, use runtime.lastError to get the error message. If the port was disconnected due to an error, then the Port argument will contain an error property giving more information about the error: The listener function will be passed the Port object. This event will only be fired once for each port. Listener functions will be called when the other end has called Port.disconnect(). If the port was disconnected due to an error, this will be set to an object with a string property message, giving you more information about the error. If this port is connected to a native application, this function will close the native application. This is useful if the other end is maintaining some state relating to this port, which can be cleaned up on disconnect. It will cause onDisconnect to be fired at the other end. Either end can call this when they have finished with the port. If this port is connected to a native application, its name is the name of the native application. The port's name, defined in the nnect() or nnect() call that created it. They contain the following properties: name You need to use different connection APIs for different sorts of connections, as detailed in the table below. between your extension and a different extension.between your extension and a native application running on the user's computer.different parts of your extension (for example, between content scripts and background scripts).You can use this pattern to communicate between: When they are finished, either end can disconnect using Port.disconnect(), which will generate a Port.onDisconnect event at the other end, enabling the other end to do any cleanup required. Once both sides have Port objects, they can exchange messages using Port.postMessage() and Port.onMessage. This is passed a corresponding Port object. The other side listens for connection attempts using an onConnect listener. One side initiates the connection, using a connect() API. Differences between API implementationsĪ Port object represents one end of a connection between two specific contexts, which can be used to exchange messages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |