1

I am trying to figure out why I am not able to use jQuery in my extension, I am an absolute beginner, but in theory this should do the job:

manifest

{
    "manifest_version": 2,
    "name" : "iD",
    "version" : "0.1",
    "description" : "iD",
    "browser_action" : {
        // "default_icon" : "icon.png",
        "default_popup" : "popup.html",
        "default_title" : "iD"
    },
    "content_scripts": [ {
        "js": [ "jquery.min.js", "app.js" ],
        "matches": [ "http://*/*", "https://*/*"]
    }]
}

popup.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

</body>
</html>

app.js

$("body").append("Hello World");

Yet all I see is an empty popup instead of "Hello World"

Ilja
  • 44,142
  • 92
  • 275
  • 498

1 Answers1

4

You can't inject content scripts into extension pages (popup included).

You need to:

  1. Read the Architecture Overview.

  2. Add the scripts directly to your popup:

    <script src="jquery.min.js"></script>
    <script src="app.js"></script>
    
  3. (the comment raises a valid point) For all DOM manipulation, wrap your code in the ready() event:

    $(document).ready(function() {
      /* Manipulate DOM here */
    });
    
Xan
  • 74,770
  • 16
  • 179
  • 206