Skip to content

Commit 91767dd

Browse files
committed
initial commit
0 parents  commit 91767dd

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This Chrome extension shows a [pageaction](https://developer.chrome.com/extensions/pageAction#method-show) when the [RTCPeerConnection API](http://w3c.github.io/webrtc-pc/) is used.
2+
Read the blogpost on webrtcH4cKs for a detailed description of how it works.
3+
4+
## Limitations
5+
It does not work for sandboxed iframes [as described here](https://github.com/diafygi/webrtc-ips/pull/8).
6+
7+
## Credits
8+
The WebRTCBlock 1.0 extension showed how to inject Javascript.
9+
10+
## License
11+
MIT

background.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chrome.runtime.onConnect.addListener(function (channel) {
2+
channel.onMessage.addListener(function (message, port) {
3+
if (message[0] !== 'WebRTCSnoop') return;
4+
console.log(new Date(), message[1], message[2]);
5+
chrome.pageAction.show(port.sender.tab.id);
6+
});
7+
});

manifest.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"content_scripts": [ {
3+
"js": [ "snoop.js" ],
4+
"matches": [ "http://*/*", "https://*/*" ],
5+
"all_frames": true,
6+
"match_about_blank": true,
7+
"run_at": "document_start"
8+
} ],
9+
"background": {
10+
"scripts": ["background.js"],
11+
"persistent": false
12+
},
13+
"page_action": {
14+
"default_icon": "icon_48.png",
15+
"default_title": "This site uses WebRTC."
16+
},
17+
"manifest_version": 2,
18+
"name": "WebRTC Notifier",
19+
"version": "0.0.1"
20+
}

snoop.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var inject = '('+function() {
2+
// taken from adapter.js, written by me
3+
['createOffer', 'createAnswer',
4+
'setLocalDescription', 'setRemoteDescription'].forEach(function(method) {
5+
var nativeMethod = webkitRTCPeerConnection.prototype[method];
6+
webkitRTCPeerConnection.prototype[method] = function() {
7+
// TODO: serialize arguments
8+
var self = this;
9+
this.addEventListener('icecandidate', function() {
10+
//console.log('ice candidate', arguments);
11+
}, false);
12+
window.postMessage(['WebRTCSnoop', window.location.href, method], '*');
13+
return nativeMethod.apply(this, arguments);
14+
};
15+
});
16+
}+')();';
17+
var script = document.createElement('script');
18+
script.textContent = inject;
19+
(document.head||document.documentElement).appendChild(script);
20+
script.parentNode.removeChild(script);
21+
22+
var channel = chrome.runtime.connect();
23+
window.addEventListener('message', function (event) {
24+
if (typeof(event.data) === 'string') return;
25+
if (event.data[0] !== 'WebRTCSnoop') return;
26+
channel.postMessage(event.data);
27+
});

0 commit comments

Comments
 (0)