V
V
Vadim)))2021-10-27 02:42:00
JavaScript
Vadim))), 2021-10-27 02:42:00

Why does it throw Uncaught TypeError: Cannot read properties of undefined (reading 'split')?

I made an extension, wrote the code:

let changeColor = document.getElementById('buttonBg');

if (changeColor != null) {
  changeColor.onclick = function(el) {  //ругается на эту строку.
    let colorBg = '#333';
    let colorText = '#fff'

    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
      chrome.tabs.executeScript(
        tabs[0].id,
        {code: 'document.body.style.backgroundColor = "' + colorBg + '";document.body.style.color = "' + colorText + '"'}
      );
    })
  }
}


I include the code not in the html page, but in manifest.json, so I can't use onload and defer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-10-27
@Aetae

onload- can. Just not . True, this is not necessary, for it is indicated when to run it in the parameter . Similarly, not , but . In general, forget about when you climb on other people's pages. There can be only one such handler, while there can be as many as you like. Well, I don’t see anywhere in your code that the error is complaining about, so somewhere you are lying. onload addEventListener('load', ...)
split

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question