JavaScript syntax error, row 1, column 1

Hi, I am trying to write a small add-on, which replaces several words on page with another. it is a political joke in a minor central-European language. When I try to upload, I got a message:

Your add-on failed validation with 1 error.

  • JavaScript syntax error.

It should be in row 1, column 1 of my JS file. I will not lie. According to validator, there are some minor issues in my code (1 unexpected for, 1 row longer than 80 char). But not in row 1, column 1. Here is my code (shortened):

var bab = ["Premiér Andrej Babiš",
"Premiéra Andreje Babiše",
...
"Babiš"

];

var bur = [“Agent StB Bureš”,
…
“Bureš”
];

function replacer (first, second) {

var reg = new RegExp(first, “g”);

var elements = document.getElementsByTagName("*");

for (var i = 0; i < elements.length; i++) {
var element = elements[i];

for (var j = 0; j < element.childNodes.length; j++) {
    var node = element.childNodes[j];

    if (node.nodeType === 3) {
        var text = node.nodeValue;
        var replacedText = text.replace(reg, second);

        if (replacedText !== text) {
            element.replaceChild(document.createTextNode(replacedText), node);
        }
    }
}

}
}

for (var i = 0; i < bab.length; i++){
replacer (bab[i], bur[i]);
}

The add-on works OK in the temporary mode. How to change it to pass test? It is my first attempt to make a Firefox add-on.

So your code is a bit all over the place with formatting here on discourse, if you’d be so kind and use code blocks that’d be great.

Apart from that I have two things that stand out:

  • ensure your file is encoded with UTF-8 and not some other encoding
  • the "g" in your regexp has the wrong double quotes, but I assume that’s due to them not being in a code block and that you actually have the correct quotes.

Further it sounds like you’re submitting a minified version of your code.
You can always run the linter using web-ext lint locally.

1 Like

I had difficulty parsing the post, and there may be other problems involved, but the first thing I thought of when I saw “row 1 column 1” is a BOM (Byte Order Mark) issue. So I would expand that to "ensure your text editor is UTF-8 without BOM

Thank you both very much!