Skip to content

Instantly share code, notes, and snippets.

@gonzalovazquez
Last active February 8, 2019 15:58
Show Gist options
  • Save gonzalovazquez/f7d6055fb76231a8150796364419e5f3 to your computer and use it in GitHub Desktop.
Save gonzalovazquez/f7d6055fb76231a8150796364419e5f3 to your computer and use it in GitHub Desktop.
Chrome Extension - 2 way communication
'use strict';
function sendMessage() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, "Background page started.");
});
}
function update() {
console.log('update')
sendMessage();
};
chrome.browserAction.onClicked.addListener(update);
chrome.runtime.onMessage.addListener(function(msg) {
console.log(msg);
});
console.log('Hello from Content Script');
chrome.runtime.sendMessage({ horde: true });
chrome.runtime.onMessage.addListener(function(msg, _, sendResponse) {
console.log("Got message from background page: " + msg);
});
{
"name": "Earth Particle",
"version": "0.0.1",
"manifest_version": 2,
"description": "This extension adds chaos to your project",
"homepage_url": "http://telus.com",
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"default_locale": "en",
"background": {
"scripts": [
"src/background.js"
],
"persistent": true
},
"browser_action": {
"default_title": "Release Chaos"
},
"permissions": [
"contentSettings",
"tabs",
"https://*/*",
],
"content_scripts": [
{
"matches": [
"https://*/*"
],
"js": [
"src/contentscript.js"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment