Your approach to this problem is incorrect. To do this, you need to go through, although the document only changes the text nodes, and not the HTML of all nodes.
By changing the code from this other answer of mine , the following full extension changes all the relevant words on the page to buttons.
Extension in action:

manifest.json
{ "description": "Upon action button click, make all matching words buttons.", "manifest_version": 2, "name": "Button all matching words", "version": "0.1", "permissions": [ "activeTab" ], "background": { "scripts": [ "background.js" ] }, "browser_action": { "default_icon": { "32": "myIcon.png" }, "default_title": "Make Buttons of specified words" } }
background.js:
chrome.browserAction.onClicked.addListener(function(tab) {
contentScript.js:
(function(){ var keywords = ["sword", "gold", "yellow", "blue", "green", "china", "civil", "state"];
myIcon.png:

The code in handleTextNode , to make changes to the text nodes, was changed from the code of my other answer .
source share