【问题标题】:Why is this extension not working offline? (code included)为什么这个扩展不能离线工作? (包括代码)
【发布时间】:2013-05-14 03:52:06
【问题描述】:

我创建了一个扩展程序(参见下面的代码),并通过“加载解压扩展程序”将其添加到 google chrome。然后我打开它并在关闭 Web 服务器(它是一个内部服务器)之前使用它。当我点击使用该应用程序时,它只是在“请求”时挂起。如何强制它仅在本地离线使用该应用?

我什至从计算机上拔下以太网(没有 wifi),所有其他扩展都是灰色的,但我的保持颜色不变,但是当我点击它时,它抛出了错误:

The app is currently unreachable.

为什么?

ma​​nifest.js

{
    "name": "Test App",
    "description": "Something",
    "version": "0.0.0.3",
    "manifest_version": 2,
    "app": {
        "urls": [
            "*://192.168.1.100/chrome/app/"
        ],
        "launch": {
            "web_url": "http://192.168.1.100/chrome/app/"
        }
    },
    "icons": {
        "128": "icon.png"
    },
    "offline_enabled": true,
    "permissions": [
        "unlimitedStorage",
        "notifications"
    ]
}

index.html

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

【问题讨论】:

    标签: google-chrome google-chrome-extension google-chrome-devtools


    【解决方案1】:

    问题在于清单文件有两种不同类型,而您都需要这两种文件(谷歌的文档从未提及这一点!)。

    第一个清单是 chrome 应用 manifest.json。我在上面的代码中有这个。虽然此清单文件旨在告诉 Chrome 应用程序所在的文件/网址并应缓存(以确保离线可用性),但它不会。这由托管服务器上的“.manifest”文件处理,并且必须是“text/manifest”类型的文件。以下是让您的 Chrome 应用离线工作的步骤:

    将 MIME 类型“文本/清单”添加到您的服务器

    (在 Apache 中,您可以将以下内容添加到 httpd.conf 或 .htaccess):

    AddType text/cache-manifest .manifest
    

    它不需要命名为“.manifest”,但这样添加 mimetype 更容易

    将链接到 index.html 的清单设置为指向 清单而不是 manifest.json:

    <!DOCTYPE html>
    <html manifest="mymanifest.manifest">
    

    创建清单文件

    CACHE MANIFEST
    
    # These are the files that will be cached and available offline
    # Their paths are relative to the manifest file
    # These files will all load from AppCache and NOT from the server, BUT
    # if you want to update them, simply change the manifest file and the browser
    # will redownload them
    CACHE:
    index.html
    icon.png
    
    # This would be files that are not cached but live only online
    NETWORK:
    
    # Files that are used if any other files cannot be loaded
    # example:
    #       someimage.png fallbackimage.png
    FALLBACK:
    

    就是这样。一旦用户在线访问过该应用一次,Chrome 就会正确缓存所有内容,并且可以离线使用。

    【讨论】:

      猜你喜欢
      • 2014-12-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 2012-07-13
      • 1970-01-01
      相关资源
      最近更新 更多