ryanmewhorter
ryanmewhorter

Reputation: 146

Chrome Extension won't load my JavaScript from the popup file

I'm working on building a Chrome extension for a forum, but the problem is the JavaScript for my popup.html won't do anything. I added alert("popup.js running...") at the top and it does come up but then my popup doesn't display at all. This is a problem because JavaScript is going to be required for the popup page. I'm kind of lost, so I'm assuming I'm just missing something that is preventing my JavaScript from running. I heard the AdBlock extension would prevent it from running but I removed that and it still didn't work. Anyone see a problem?

manifest.json

{
    "name": "Riggy",
    "short_name": "Riggy",
    "description": "Create your own Roblox Forum signature with Riggy!",
    "version": "0.0.1",
    "manifest_version": 2,
    "browser_action": {
        "default_popup": "popup/popup.html"
    },
    "permissions": [
        "storage"
    ],
    "content_scripts": [
        {
            "matches": ["http://www.roblox.com/*"],
            "js": ["scripts/jquery.js", "scripts/content.js"]
        }
    ]
}

popup.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="popup.css" />
        <script type="text/javascript" src="scripts/jquery.js"></script>
    </head>
    <body>
        <span class="title">Riggy</span><br />
        <span>Signature: </span><input name="siggy" id="siggy" value="Riggy is greatness!" />
        <span id="output">[output]</span>
        <script type="text/javascript" src="popup.js"></script>
    </body>
</html>

popup.js

alert("popup.js running");
$(document).on("ready", function() {
    var siggy = $("#siggy");
    var output = $("#output");

    function message(text) {
        output.html(text);
    }

    siggy.change(function() {
        chrome.storage.sync.set({"siggy": siggy.val()}, function() {
            message("Saved signature.");
        });
    });

    message("Riggy is ready!");
});

Upvotes: 2

Views: 2026

Answers (1)

Fauxsaurus
Fauxsaurus

Reputation: 520

I had the same exact problem with an extension of mine, I believe it was fixed after I added this to the manifest file.

manifest.json

"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"

More info here: http://developer.chrome.com/extensions/contentSecurityPolicy.html.

Upvotes: 1

Related Questions