Ashish S Panicker
Ashish S Panicker

Reputation: 11

Javascript not working in a google chrome extension

I am trying to create a simple extension for google chrome. I am including the code that I have used. But the script included is not working.

index.html

<!doctype html>
<html>
<head>
      <script src="ext.js"></script>
</head>
<body>
      <button id='test'>Test</button>
<body>
</html>

manifest.json

{
  "name": "Demo Extension",
  "description": "Demo Extension",
  "version": "1.0",
  "permissions": ["tabs", "http://*/*", "https://*/*"],
  "browser_action": {
      "default_title": "Demo",
      "default_popup": "index.html"
  },
  "content_security_policy":"script-src 'self' https://localhost; object-src 'self'",
  "manifest_version": 2
}

ext.js

function clickHandler(e) {
  alert('its working');
}

document.addEventListener('DOMContentReady', function () {

  document.querySelector('button')
          .addEventListener('click', clickHandler);
});

How can I resolve this?

Upvotes: 1

Views: 89

Answers (1)

Vincent Scheib
Vincent Scheib

Reputation: 18650

It's DOMContentLoaded rather than DOMContentReady - devnull69

Upvotes: 1

Related Questions