Created
March 1, 2014 23:17
-
-
Save Noitidart/9299123 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-OpenNewTabGetIframeHtml - This snippet must run in privelaged scope. It opens a new tab and messages you when it loads, and it looks for all iframes in that new tab and messages you when iframes contentDocument is ready and populated. I do need a better way to test if iframe is loading/loaded on initial run of the getIframeHtml…
This file contains hidden or 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
| Components.utils.import('resource://gre/modules/Services.jsm') | |
| var aDOMWindow = Services.wm.getMostRecentWindow('navigator:browser'); | |
| var newTabBrowser = aDOMWindow.gBrowser.getBrowserForTab(aDOMWindow.gBrowser.loadOneTab('http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_tolocaletimestring', { | |
| inBackground: false | |
| })); | |
| newTabBrowser.addEventListener('load', function onloadFunc() { | |
| Services.appShell.hiddenDOMWindow.console.log('tab loaded'); | |
| newTabBrowser.removeEventListener('load', arguments.callee, true); | |
| var doc = newTabBrowser.contentDocument; | |
| var win = doc.defaultView; | |
| var iframes = doc.querySelectorAll('iframe'); | |
| Services.appShell.hiddenDOMWindow.console.log('number of iframes in this tab = ' + iframes.length); | |
| [].forEach.call(iframes, function (frm, i) { | |
| logIframeHtml(frm, i); | |
| }); | |
| }, true); | |
| function logIframeHtml(iframe, i) { | |
| iframe.removeEventListener('DOMContentLoaded', logIframeHtml, true); //this line removes the event listneer if it had one | |
| var iframeDoc = iframe.contentDocument; | |
| if (!iframeDoc) { | |
| Services.appShell.hiddenDOMWindow.console.log('iframe ' + i + ' is not fully loaded yet as it its contentDocument does not exist'); | |
| iframe.addEventListener('DOMContentLoaded', logIframeHtml, true); | |
| } else { | |
| var iframeInnerHtml = iframeDoc.documentElement.innerHTML; | |
| Services.appShell.hiddenDOMWindow.console.log('iframe ' + i + ' innerHTML = ' + iframeInnerHtml); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment