Last active
October 31, 2022 14:11
-
-
Save atmd83/ebbe0f9820ac9521e1fd to your computer and use it in GitHub Desktop.
Demo for cross-extension messaging in chrome extensions
This file contains hidden or 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
chrome.runtime.onMessageExternal.addListener(function(request, sender, sendResponse) { | |
console.log('incomming'); | |
if (request.getTargetData){ | |
console.log('We have target data'); | |
sendResponse({targetData: {}}); | |
} else { | |
if (request.activateLasers) { | |
var success = true; | |
console.log('lazers active'); | |
sendResponse({activateLasers: success}); | |
} | |
} | |
}); |
This file contains hidden or 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
var id = "[ID FOR APP ONE]"; | |
console.log('target data sent'); | |
chrome.runtime.sendMessage(id, {getTargetData: true}, function(response) { | |
if (response.targetData) | |
console.log('activate the weapons'); | |
chrome.runtime.sendMessage(id, {activateLasers: true}); | |
}); |
This file contains hidden or 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
{ | |
"manifest_version": 2, | |
"name": "comunication app", | |
"description": "Testing chrome cross extension comunication", | |
"version": "2.0.20", | |
"background": { | |
"scripts": ["background.js"] | |
}, | |
"browser_action": { | |
"default_icon": "icon.png", | |
"default_popup": "popup.html", | |
"default_title": "Click here!" | |
}, | |
"permissions": [ | |
"activeTab", | |
"https://ajax.googleapis.com/", | |
"tabs", | |
"http://*/*", "https://*/*", "background" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment