get an iframe directly to bypass overrides, thanks to upsuper
This commit is contained in:
parent
108160ef73
commit
bc6099ed96
2 changed files with 15 additions and 44 deletions
29
README.md
29
README.md
|
@ -23,29 +23,14 @@ function getIPs(callback){
|
|||
|| window.webkitRTCPeerConnection;
|
||||
var useWebKit = !!window.webkitRTCPeerConnection;
|
||||
|
||||
//bypass naive webrtc blocking
|
||||
//bypass naive webrtc blocking using an iframe
|
||||
if(!RTCPeerConnection){
|
||||
//create an iframe node that doesn't allow plugins
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.style.display = 'none';
|
||||
iframe.sandbox = 'allow-same-origin allow-scripts';
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
//create a nested iframe that doesn't allow javascript
|
||||
var iframe2 = iframe.contentDocument.createElement("iframe");
|
||||
iframe2.sandbox = 'allow-same-origin';
|
||||
|
||||
//add a listener to cutoff any attempts to disable webrtc when inserting to the DOM
|
||||
iframe2.addEventListener("DOMNodeInserted", function(e){
|
||||
e.stopPropagation();
|
||||
}, false);
|
||||
iframe2.addEventListener("DOMNodeInsertedIntoDocument", function(e){
|
||||
e.stopPropagation();
|
||||
}, false);
|
||||
|
||||
//get the RTCPeerConnection connection from the nested iframe
|
||||
iframe.contentDocument.body.appendChild(iframe2);
|
||||
var win = iframe2.contentWindow;
|
||||
//NOTE: you need to have an iframe in the page right above the script tag
|
||||
//
|
||||
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
||||
//<script>...getIPs called in here...
|
||||
//
|
||||
var win = iframe.contentWindow;
|
||||
RTCPeerConnection = win.RTCPeerConnection
|
||||
|| win.mozRTCPeerConnection
|
||||
|| win.webkitRTCPeerConnection;
|
||||
|
|
30
index.html
30
index.html
|
@ -19,6 +19,7 @@
|
|||
<ul></ul>
|
||||
<h4>Your public IP addresses:</h4>
|
||||
<ul></ul>
|
||||
<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
||||
<script>
|
||||
//get the IP addresses associated with an account
|
||||
function getIPs(callback){
|
||||
|
@ -30,29 +31,14 @@
|
|||
|| window.webkitRTCPeerConnection;
|
||||
var useWebKit = !!window.webkitRTCPeerConnection;
|
||||
|
||||
//bypass naive webrtc blocking
|
||||
//bypass naive webrtc blocking using an iframe
|
||||
if(!RTCPeerConnection){
|
||||
//create an iframe node that doesn't allow plugins
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.style.display = 'none';
|
||||
iframe.sandbox = 'allow-same-origin allow-scripts';
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
//create a nested iframe that doesn't allow javascript
|
||||
var iframe2 = iframe.contentDocument.createElement("iframe");
|
||||
iframe2.sandbox = 'allow-same-origin';
|
||||
|
||||
//add a listener to cutoff any attempts to disable webrtc when inserting to the DOM
|
||||
iframe2.addEventListener("DOMNodeInserted", function(e){
|
||||
e.stopPropagation();
|
||||
}, false);
|
||||
iframe2.addEventListener("DOMNodeInsertedIntoDocument", function(e){
|
||||
e.stopPropagation();
|
||||
}, false);
|
||||
|
||||
//get the RTCPeerConnection connection from the nested iframe
|
||||
iframe.contentDocument.body.appendChild(iframe2);
|
||||
var win = iframe2.contentWindow;
|
||||
//NOTE: you need to have an iframe in the page right above the script tag
|
||||
//
|
||||
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
||||
//<script>...getIPs called in here...
|
||||
//
|
||||
var win = iframe.contentWindow;
|
||||
RTCPeerConnection = win.RTCPeerConnection
|
||||
|| win.mozRTCPeerConnection
|
||||
|| win.webkitRTCPeerConnection;
|
||||
|
|
Loading…
Reference in a new issue