0

I'm making a chrome extensions, and some of the functions that I'm going to have will make use of jQuery. I've had trouble finding a working solution online.

core.js:

$(document).ready(function(){
init();
});

function init()
{
    $(":button").click(function(){
        console.log("test");
        //more code here...
    });
}

extension.html:

<html>
<head>
<title>awesome</title>
<script src="scripts/core.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
</head>
<body>
<button id="getThem">GET!</button>
</body>
</html>

In my manifest I have the name, version, manifest_version (2), description, browser_action->default_popup (extention.html) and I'm not sure what to put for the rest. Can you help me piece together these basic elements?

Lebowski156
  • 951
  • 5
  • 11
  • 34

1 Answers1

1

A page in the Chrome extension process cannot load external scripts, because of the Content Security policy. If you inspect the popup, the console would have revealed this error.

The best solution is to bundle (jQuery) library with your extension - this has no additional cost, and makes your popup load faster.

If you really want to embed scripts from an external URL, relax the Content Security policy, e.g..

"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'"

This can only be done for the https scheme. If you want to load from a http resource, you're out of luck (there is actually a work-around, but please don't use it.).

Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • PS. Here's a screencast that shows how to identify and solve the problem: http://stackoverflow.com/questions/17601615/the-chrome-extension-popup-is-not-working-click-events-are-not-handled/17612988#17612988 – Rob W Jul 26 '13 at 19:41