Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
Can't access chrome extension DOM elements from service worker

I'm trying to make a chrome extension that when you click a button opens a popup. I can open it with a function through the console but when connecting it to a button in the popup.html file and trying it out it gives out these errors:

First error :

enter image description here

Second error :

enter image description here

I have tried a couple of different ways to do it but none of them have worked so far. Does anyone know what the problem is with my code?

popup.html

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="popup.css">
    <script defer src="background.js"></script>
  </head>
  <body>
    <h2>Click to Make New Sticky Note.</h2>
    <button id="newNoteButton">Press</button>
  </body>
</html>

background.js

const newNoteButton = document.getElementById('newNoteButton')
const windowData = {
    'type': "popup",
    'url': "http://www.google.com"
}

function createNewNote() {
    chrome.windows.create(windowData)
}

newNoteButton.addEventListener('click', createNewNote())

manifest.json

{
    "name": "Sticky Froggies",
    "description": "Sticky Notes. Now with Frogs!",
    "version": "1.0",
    "manifest_version": 3,
    "background": {
      "service_worker": "background.js"
    },
    "permissions": ["tabs", "storage"],
    "action": {
      "default_popup": "popup.html"
    }
  }

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda