Gregor
Gregor

Reputation: 39

Chrome Extension js code works only in console

I'm very new to making chrome extension, not sure why but my javascript code returns on start

Cannot read properties of undefined

(reading cells), but in console everything works fine.

if(document.getElementById('pricelist')){
    var elementTable = document.getElementById('pricelist').tBodies[0];

    for (let i = 0; i < 25; i++) {
        for (let x = 1; x < 14; x++){
            let value = parseInt(elementTable.rows[i].cells[x].innerText);
            let mainValue = parseInt(elementTable.rows[i].cells[2].innerText);
            let diference = mainValue - value;
            let percentage = (diference/steamValue)*100;
            let newValue = value + "(" + percentage + ")";
            document.getElementById('pricelist').tBodies[0].rows[i].cells[x].innerHTML = newValue
        }    
    }
}

json:

{
    "name": "calculator",
    "version": "1.0",
    "manifest_version": 2,
    "content_scripts": [
        {
            "matches": ["https://cmywebsite.com"],
            "js": ["content.js"]
        }
    ]
}

Upvotes: 1

Views: 98

Answers (1)

Gregor
Gregor

Reputation: 39

Turns out a website I was using on had Web Scaping detection and was blocking me

Upvotes: 1

Related Questions