I'm creating a extension for Safari that need make some changes on content of a active tab using innerHTML
in specific places of this content.
But for make this, is necessary before retrieve all html content including all tags and texts.
I have a Chrome Extension, that function below works very fine! but in Safari browser don't works :-(
This works fine to Google Chrome, but not for Safari:
This works fine to Google Chrome, but not for Safari:
function DOMtoString(document_root) {
var html = '',
node = document_root.firstChild;
while (node) {
switch (node.nodeType) {
case Node.ELEMENT_NODE:
html += node.outerHTML;
break;
case Node.TEXT_NODE:
html += node.nodeValue;
break;
case Node.CDATA_SECTION_NODE:
html += '<![CDATA[' + node.nodeValue + ']]>';
break;
case Node.COMMENT_NODE:
html += '<!--' + node.nodeValue + '-->';
break;
case Node.DOCUMENT_TYPE_NODE:
// (X)HTML documents are identified by public identifiers
html += "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';
break;
}
node = node.nextSibling;
}
return html;
}
So, someone know how make this same think (get full html source) on Safari across a extension?