Skip to content

🥬 | Demonstration of turning chrome.runtime.connectNative's functions into sync function

Notifications You must be signed in to change notification settings

pandasoli/sync-chrome-native-messaging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

non-Async Native Messaging

This is an example of how you can simplify your interactions with the native host.


How it works

In the background.js we have a connect() function. It creates the port, and two listeners, for messages and errors, and then it sends a message to test the connection.

The function returns a promise (i.e. an async function that throws errors) that keeps waiting until the connection try gets a response.

This was made because the messages and errors are not received instantly.
This is a way of sleep to return the function whenever we want.


In chrome.runtime.onMessage we wait for messages (a string) from the popup. If it receives 'connect' it calls the connect() function and returns true - used when we want to return asynchronous - because now we want to wait the connect() function to respond, then we return the error.

About

🥬 | Demonstration of turning chrome.runtime.connectNative's functions into sync function

Topics

Resources

Stars

Watchers

Forks