1

I'm currently developing a Chrome extension but my it doesn't seem to be able to execute any Javascript.

$(document).ready(function () {
    $("#overlay").hide();
});

In this example I'm trying to hide a div with id "overlay" but it doesn't seem to be working. Stored in an external file (popup.js)

Manifest:

{
    "name": "Test",
    "version": "0.0.1",
    "manifest_version": 2,
    "description": "",
    "offline_enabled": true,
    "background": {
     "scripts": [
         "js/background.js"
           ]
    },
    "icons": { "16": "android-16.png",
           "48": "android-48.png",
           "128": "android-128.png"
    },
    "browser_action": {
        "default_icon" : "android-128.png",
        "default_title": "",
        "default_popup": "index.html"
    },
    "permissions": [
        "background", "unlimitedStorage", "tabs"
    ],
    "web_accessible_resources": [
    "index.html","js/popup.js"
    ]
}

HTML links situated before body closing tags:

<script src="js/background.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="js/popup.js"></script>
Arthelon
  • 36
  • 1
  • 5
  • Forgot to mention, js files are all stored in a folder within the directory called "js" – Arthelon Apr 18 '15 at 05:01
  • Download jQuery and load it like you are loading your scripts. – abraham Apr 18 '15 at 11:54
  • Answered a similar question here: http://stackoverflow.com/a/29678547/934239 Can't choose as duplicate as it's not upvoted. – Xan Apr 18 '15 at 14:50
  • possible duplicate of [Use Angular tags inside google chrome devtool panel](http://stackoverflow.com/questions/29670938/use-angular-tags-inside-google-chrome-devtool-panel) – Xan Apr 18 '15 at 15:37

1 Answers1

1

Just as @Xan mentioned due to the CSP will block the script the best way to avoid this and do it work is downloading jquery.js and make it part of your extension.

nramirez
  • 5,230
  • 2
  • 23
  • 39
  • Hey, @Xan could you be more specific? neither downloading jquery.js and adding it to the extension doesn't work for you? – nramirez Apr 18 '15 at 15:16
  • No, the first part. Adding permissions won't help, [CSP will block the script](https://developer.chrome.com/extensions/contentSecurityPolicy#resourceLoading). There is a way around that, but as is your answer is half-incorrect. And it was fully incorrect before your edit. – Xan Apr 18 '15 at 15:17
  • Thanks @Xan I fixed it, but I think this question can be marked as duplicate as you mentioned in your comment. – nramirez Apr 18 '15 at 15:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75590/discussion-between-nramirez-and-xan). – nramirez Apr 18 '15 at 15:37