0

I'm currently building a chrome extension using javascript. I need to run a script to get the input element of the active tab, so in my background/index.js file, I tried to do a document.querySelector("#subBtn") but I received:

Uncaught ReferenceError: document is not defined Context background.js Stack Trace background.js:1 (anonymous function)

const subBtn = document.querySelector("#subBtn");
const resetBtn = document.querySelector('.reset');
const intputPart = document.querySelector("#form");

window.resetBtn.addEventListener('click', () => {
    intputPart.style.display = "block";
    location.reload();

})
.....

1 Answers1

1

Chrome extensions don't run in the context of the web page, so they don't have a global document variable.

If you want to modify the DOM of the current page, you can use a content script.

Thomas
  • 174,939
  • 50
  • 355
  • 478