0

I created a chrome extension to replace "textA" with "textB" and it's working, but I'm having issues loading photos on some pages. Looks like it's replacing "textA" in the photo link as well as on the page text.

My code:

{
"name": "name",
"version": "1.0",
"permissions": [
  "tabs", "<all_urls>"
],
"content_scripts": [
  {
  "matches": ["<all_urls>"],
  "js": ["content.js"],
  "run_at": "document_end"
  }
],
"manifest_version": 2
}

javascript

document.body.innerHTML = document.body.innerHTML.replace(/textA/g, "textB");
Nikislash
  • 9
  • 2
  • Do you have a question? – devnull69 May 05 '15 at 10:42
  • OK, so what's your question? – BenM May 05 '15 at 10:45
  • What taught you to use `.innerHTML = .innerHTML`? Doing so will break many web pages (as you might have discovered). See https://stackoverflow.com/a/12212700/938089 to learn how to do it properly. That question/answer is about replacing texts with links, but that is conceptually not different from replacing text with other text. – Rob W May 05 '15 at 10:46
  • possible duplicate of [Replace text in website with Chrome content script extension](http://stackoverflow.com/questions/5797661/replace-text-in-website-with-chrome-content-script-extension) – Zig Mandel May 05 '15 at 12:03
  • @ZigMandel That one use is trying to use inline javascript. They both have the same problem of trying to modify `innerHTML`. – Teepeemm May 05 '15 at 12:09
  • I know but strangely it was marked answered so i wanted to point out they are the exact same question and the other answer should be marked incorrect – Zig Mandel May 05 '15 at 12:11

0 Answers0