OLD | NEW |
1 // Content script that echoes back all messages. | 1 // Content script that echoes back all messages. |
2 // Posting a message with "GET" returns the name and # of connections opened. | 2 // Posting a message with "GET" returns the name and # of connections opened. |
3 var connections = 0; | 3 var connections = 0; |
4 | 4 |
5 chrome.extension.onConnect.addListener(function onConnect(port) { | 5 chrome.runtime.onConnect.addListener(function onConnect(port) { |
6 connections++; | 6 connections++; |
7 port.onMessage.addListener(function onMessage(msg) { | 7 port.onMessage.addListener(function onMessage(msg) { |
8 if (msg == "GET") { | 8 if (msg == "GET") { |
9 port.postMessage({"name": port.name, "connections": connections}); | 9 port.postMessage({"name": port.name, "connections": connections}); |
10 } else { | 10 } else { |
11 port.postMessage(msg); | 11 port.postMessage(msg); |
12 } | 12 } |
13 }); | 13 }); |
14 }); | 14 }); |
15 | 15 |
16 chrome.extension.onRequest.addListener(function(request, sender, respond) { | 16 chrome.extension.onRequest.addListener(function(request, sender, respond) { |
17 respond(request); | 17 respond(request); |
18 }); | 18 }); |
OLD | NEW |