Last active
February 8, 2019 15:58
-
-
Save gonzalovazquez/f7d6055fb76231a8150796364419e5f3 to your computer and use it in GitHub Desktop.
Chrome Extension - 2 way 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
'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); | |
}); |
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
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); | |
}); |
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
{ | |
"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