background.html与background.js-chrome扩展

don*_*yor 6 html javascript google-chrome google-chrome-extension

我真的很困惑。我试图了解chrome扩展的文件体系结构。我正在阅读此文档:https : //developer.chrome.com/extensions/overview#arch

我的情况:

我想设置oauth流,以便用户可以在扩展内登录(另一个端点是我的django后端)。到目前为止,我有以下文件:

background.js 
content.js
popup.html
manifest.json
Run Code Online (Sandbox Code Playgroud)

我的content.js将消息发送到background.js并获得响应。到目前为止一切顺利!

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

"background": {
"persistent": false,
"scripts": ["jquery111.js", "background.html"]
Run Code Online (Sandbox Code Playgroud)

扩展程序不再起作用。在OAuth文档中,它表示:

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.
Run Code Online (Sandbox Code Playgroud)

但是在架构文档中,它说:

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.
Run Code Online (Sandbox Code Playgroud)

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

Gra*_*ICA 5

你只允许指定任意脚本的数组...

"background": {
    "persistent": false,
    "scripts": [ "jquery111.js"]
}
Run Code Online (Sandbox Code Playgroud)

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

"background": {
    "persistent": false,
    "page": "background.html"
}
Run Code Online (Sandbox Code Playgroud)

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

"background": {
    "persistent": false,
    "scripts": [ "jquery111.js"]
}
Run Code Online (Sandbox Code Playgroud)

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

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