Last active
October 18, 2018 19:09
Chrome App to Webpage communication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// be sure to update manifest to allow external connections, | |
// https://developer.chrome.com/extensions/messaging#external-webpage | |
/* | |
"externally_connectable" : { | |
"matches": ["*://diyability-capacita.appspot.com/*"] | |
} | |
*/ | |
// Listen for incoming long lasting PORT connection from Webpage or extension | |
chrome.runtime.onConnectExternal.addListener(function(port) { | |
console.log("PORT!", port); | |
// say hello every second once connection is made | |
setInterval(function() { | |
port.postMessage("hi from chrome app"); | |
console.log("trying to say hi") | |
}, 1000); | |
port.onMessage.addListener(function(msg) { | |
// See other examples for sample onMessage handlers. | |
console.log("msg received: ", msg); | |
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put this in your webpage js | |
var extId = "gdbjlnnacemphcbgjhlcjjjcnijafpgi"; // chrome app id | |
var port = chrome.runtime.connect(extId); | |
port.postMessage("hi from webpage"); | |
port.onMessage.addListener(function(msg) { | |
// See other examples for sample onMessage handlers. | |
console.log("web page received: ", msg); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment