Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda