Chrome扩展程序:无法加载JavaScript文件 [英] Chrome extension: Could not load javascript file

查看:529
本文介绍了Chrome扩展程序:无法加载JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了另一个关于我的Chrome扩展程序的问题 by Rob Wu



这里的问题在于,您已经将压缩的CRX文件上传到您的ZIP文件,而不是您的扩展程序源代码。您应该上传包含您的扩展程序根目录的ZIP文件。既然你已经包含了 manifest.json 文件,那么Web Store在你尝试安装扩展之前并没有注意到任何错误,因为清单写得很好,但是当Chromes尝试访问已声明的文件时,它会失败并返回错误,因为这些文件不存在。



通过Chrome网上应用店开发人员信息中心的上传页面进行引用:


上传一件商品


因此,您应该为您的扩展程序根目录创建一个 ZIP 文件,其中包含 strong>您的扩展的文件。您的ZIP文件应该如下所示:




I have posted another question regarding my Chrome extension here.
But I have one more question about extensions themselves. I only need a content script for the modification of the Tumblr-Dashboard, no background page or something else, right?

Here is the manifest.json file:

{
    "name": "Tumblr - Tiled Dashboard",
    "version": "0.0.54",
    "manifest_version": 2,
    "description": "This extension modifies the look of your Tumblr dashboard.",
    "icons": {
        "16": "images/icon_16.png",
        "48": "images/icon_48.png",
        "128": "images/icon_128.png"
    },
    "content_scripts": [
        {
            "matches": [ "*://*.tumblr.com/dashboard" ],
            "css": [ "styles.css" ],
            "js": [ "jquery-2.1.3.min.js", "masonry.min.js", "code.js" ]
        }
    ],
    "homepage_url": "mypage",
    "author":  "myname"
}

To start, I ask if this is alright? I have read a lot about the manifest.json file and everything seems to work fine when I try out the extension locally. But when I pack the extension and upload it, there are two problems:

  1. I cannot find the extension when I search for it
  2. When I use the link to find the extension, and I want to install it (tried that on 2 different PCs), I get an error, telling me that the jquery-2.1.3.min.js file could not be loaded. I therefore changed the order of my JavaScript files to test if it was a problem related to the jQuery file, but having masonry.min.js as the first file in the array resulted in the same error.

Why does this happen? Is the manifest.json file ok? Do I need some special permissions?

Edit: This is a screenshot of when I try to install the extension from the Chrome Web Store (where I also can't find it by search).

解决方案

I took a look inside your extension's ZIP file before downloading it, and the result was the following:

*Inspected using Chrome extension source viewer by Rob Wu

The problem here, is that you've uploaded a packed CRX file inside of your ZIP file, instead of your extension source code. You should instead upload a ZIP file containing your extension's root. Since that you're including the manifest.json file, the Web Store doesn't notice anything wrong until you try to install the extension, because the manifest is well written, but when Chromes tries to access the files declared, it fails and returns an error, because those files do not exist.

Quoting from the upload page of the Chrome Web Store Developer Dashboard:

Uploading an item:

So, you should create a ZIP file of your extension's root directory, containing all the files of your extension. Your ZIP file should then look like the following:

这篇关于Chrome扩展程序:无法加载JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆