background.html与background.js - chrome扩展

时间:2014-07-27 06:26:14

标签: javascript html google-chrome google-chrome-extension

我真的很困惑。我试图了解chrome扩展的文件架构。我正在阅读这份文件:https://developer.chrome.com/extensions/overview#arch

我的情况:

我想设置oauth流程,以便用户可以在扩展名内登录(另一个端点是我的django后端)。直到现在,我有这些文件:

background.js 
content.js
popup.html
manifest.json

我的content.js将消息发送到background.js并获得回复。到目前为止很好!

但是现在在阅读oauth的文档时,我很困惑,不知道background.html是什么。它实际上是应该包含我的background.js的所有js代码的文件吗?但是,如果我在清单中将其更改为.html,例如:

"background": {
"persistent": false,
"scripts": ["jquery111.js", "background.html"]

扩展程序不再有效。在OAuth doc中,它说:

Place the four library files in the root of your extension directory 
(or wherever your JavaScript is stored). Then include the .js files in your 
background page...
Your background page will manage the OAuth flow.

但在architecture doc中,它说:

This figure shows the browser action's background page, which is defined by
background.html and has JavaScript code that controls the behavior of 
the browser action in both windows.

background.html和background.js有什么区别?

1 个答案:

答案 0 :(得分:0)

仅允许您之一指定一个脚本数组...

"background": {
    "persistent": false,
    "scripts": [ "jquery111.js"]
}

... 页面,然后可以引用该页面所需的脚本:

"background": {
    "persistent": false,
    "page": "background.html"
}

理论上,您的background.html页只能是所需脚本的列表。

<script src="jquery111.js"></script>

如果您尝试同时指定两者,则扩展名将不会加载:

  

background.page和background.scripts属性不能同时使用。无法加载清单。

相关问题