even changing the innerHTML of single node is not allowed, atleast it seems like that. I am using following code and it shows me error.
_findAndReplace: function(searchText, replacement, searchNode) {
console.log("inside highlight function");
if (!searchText || typeof replacement === 'undefined') {
// Throw error here if you want...
return;
}
var vrs_getWin = document.commandDispatcher.focusedWindow;
//var bodyContents = vrs_getWin.document.getElementsByTagName("body")[0].innerHTML;
var regex = typeof searchText === 'string' ?
new RegExp(searchText, 'g') : searchText,
childNodes = (searchNode || vrs_getWin.document.body).childNodes,
cnLength = childNodes.length,
excludes = 'html,head,style,title,link,meta,script,object,iframe';
while (cnLength--) {
var currentNode = childNodes[cnLength];
if (currentNode.nodeType === 1 &&
(excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
arguments.callee(searchText, replacement, currentNode);
}
if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
continue;
}
var parent = currentNode.parentNode,
frag = (function(){
var html = currentNode.data.replace(regex, replacement),
wrap = document.createElement('div'),
frag = document.createDocumentFragment();
wrap.innerHTML = html;
while (wrap.firstChild) {
frag.appendChild(wrap.firstChild);
}
return frag;
})();
parent.insertBefore(frag, currentNode);
parent.removeChild(currentNode);
}
console.log(searchText+" Word hightlighted");
},
I am getting following error while uploading new version.
Markup should not be passed to innerHTML
dynamically.
Warning: Due to both security and performance concerns, innerHTML may not be set using dynamic values which have not been adequately sanitized. This can lead to security issues or fairly serious performance degradation.
chrome/content/highlight.js
frag = document.createDocumentFragment();
wrap.innerHTML = html;
while (wrap.firstChild) {