This adds chrome extension sample for reference.
The extension has chrome extension style manifest.json that specifies
name, background, and contentscript.
It alerts popup when click event is emitted on web app.
Also, contentscript and background communicate each other via IPC
that can be checked by inspector console.
Change-Id: I92921b05fe07f9b0bb8e88d14d26e1bc3a59af6e
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
--- /dev/null
+chrome.runtime.onConnect.addListener(function(port) {
+ console.assert(port.name == "contentscript");
+ port.onMessage.addListener(function(msg) {
+ if (msg.contentscript == "Hello background!") {
+ console.log('from contentscript : ' + msg.contentscript);
+ port.postMessage({background: "Hello contentscript!"});
+ }
+ });
+});
--- /dev/null
+var port = chrome.runtime.connect({name: "contentscript"});
+port.postMessage({contentscript: "Hello background!"});
+port.onMessage.addListener(function(msg) {
+ if (msg.background == "Hello contentscript!") {
+ console.log('from background : ' + msg.background);
+ }
+});
+
+var items = document.getElementsByTagName("*");
+for (var i = 0; i < items.length; i++) {
+ items[i].addEventListener("click", function(e) {
+ e.stopPropagation();
+ alert('hello world!');
+ });
+}
+
--- /dev/null
+{
+ "name": "chrome_extension_sample",
+ "description": "Alert",
+ "version": "2.0",
+ "background": {
+ "scripts": ["background.js"],
+ "persistent": false
+ },
+ "content_scripts": [
+ {
+ "matches": [
+ "<all_urls>"
+ ],
+ "js": ["contentscript.js"]
+ }
+ ],
+ "browser_action": {
+ "default_title": "Alert"
+ },
+ "manifest_version": 2
+}