chrome扩展程序-清单版本2 [英] chrome extension - manifest version 2

查看:91
本文介绍了chrome扩展程序-清单版本2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个chrome扩展名,该扩展名引用了jquery文件.
这是我的弹出HTML(仅head标签):

I have a chrome extension that has a reference to the jquery file.
this is my popup html (only the head tag):

<head>
    <title>My Extention</title>
    <script type="text/javascript" src="http://www.MySite.com/Resources/JS/JQuery/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="MyExtensionScript.js"></script>
</head>

所以在"MyExtensionScript.js"中,我以为我可以使用jquery,但显然$函数未定义.
这是我的manifest.json文件:

so in "MyExtensionScript.js" i thought i could use jquery but apparently the $ function is not defined.
This is my manifest.json file:

{
  "name": "My Test Extension",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Test version of My Extension",
  "browser_action": {
    "default_icon": "test.ico",
    "default_popup": "Test.html"
  },
  "permissions": [
    "cookies",
    "tabs",
    "<all_urls>"
  ]
}

在清单的版本1中有效,但现在不起作用了.我尝试使用"web_accessible_resources"并将其添加到"http://www.MySite.com/Resources/JS/JQuery/jquery-1.7.2.min.js",但这也没有用.有什么想法吗?
另外,我有一个脚本注入到当前页面并向我返回一条消息(在我的情况下,该页面的某些HTML源代码),此行为会受到向清单版本2过渡的影响吗? 谢谢大家:)

in version 1 of the manifest it worked, but now it doesn't. I tried to use the "web_accessible_resources" and add to them "http://www.MySite.com/Resources/JS/JQuery/jquery-1.7.2.min.js" but that didn't work also. any ideas?
also, i have a script injected to the current page and returning me a message (in my case some html source of the current page), will this behavior be affected by the transition to manifest version 2? Thanks all :)

编辑:我有一个启用跨域脚本编写(使用JSONP)的Web应用程序.在我的扩展程序中,我有一个脚本在我的站点中使用$ .getJSON调用Web服务.现在不起作用.我很确定这与新的清单版本有关,但是如何再次启用跨域脚本?

I have a web application that enables cross domain scripting (using JSONP). In my extension i had a script calling a web service in my site with $.getJSON. now it doesn't work. i'm pretty sure that it has to do with the new manifest version but how can i enable again the cross domain scripting?

推荐答案

您需要使用本地存储在扩展程序中的jQuery文件,而不是从您的站点引用.

You need to use a jQuery file stored locally in your extension, rather than referenced from your site.

这是由于Chrome严格的内容安全政策,该政策仅允许本地脚本无需内联代码即可执行.

This is due to Chrome's strict Content Security Policy that only allows local scripts to be executed, with no inline code.

网络可访问资源是扩展中的文件可以从网络上访问,而扩展程序可以访问网络上的资源.例如,如果您想使用扩展中存储的图像来更改页面的背景图像,则必须将该图像添加到清单中web_accessible_resouces中的列表中.

Web Accessible Resources are files inside your extension that may be accessed from the web, rather that resources your extension can access that are on the web. For example, if you wanted to change the background image of a page using an image stored in the extension, you have to add that image to the list in web_accessible_resouces in your manifest.

清单文件版本的更改不应影响您的内容脚本,除非它们执行了不再允许的操作.您可以从Chrome manifestVersion 文档中看到其他更改.

The change of manifest version should not affect your content scripts, unless they do something that is no longer allowed. You can see what else has changed from the Chrome manifestVersion docs.

这篇关于chrome扩展程序-清单版本2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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