Javascript background.html与background.js-chrome扩展

Javascript background.html与background.js-chrome扩展,javascript,html,google-chrome,google-chrome-extension,Javascript,Html,Google Chrome,Google Chrome Extension,我真的很困惑。我试图理解chrome扩展的文件体系结构。我正在读这份文件: 我的情况: 我想设置oauth流,以便用户可以登录到扩展内部(另一个端点是我的django后端)。到目前为止,我有以下文件: background.js content.js popup.html manifest.json 在这里,my content.js将消息发送到background.js并获得响应。到目前为止还不错 但是现在在阅读oauth的文档时,我不知道background.html是什么。它实际上是应

我真的很困惑。我试图理解chrome扩展的文件体系结构。我正在读这份文件:

我的情况:

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

background.js 
content.js
popup.html
manifest.json
在这里,my content.js将消息发送到background.js并获得响应。到目前为止还不错

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

"background": {
"persistent": false,
"scripts": ["jquery111.js", "background.html"]
扩展不再工作了。在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.
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.
但在这本书中,它说:

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.
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之间有什么区别

您只能指定脚本数组

"background": {
    "persistent": false,
    "scripts": [ "jquery111.js"]
}
。。。或一个页面,该页面可引用该页面所需的脚本:

"background": {
    "persistent": false,
    "page": "background.html"
}
理论上,你的
background.html
页面只能是一系列需要的脚本


如果尝试同时指定这两个选项,则扩展将不会加载:

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


您的background.html基本上只是一个后台脚本的容器,您可以简单地将其编写为
。调试扩展时,可以在Chrome的开发工具中从chrome://extensions 第页。@phette23谢谢,但是为什么在将我的清单的背景从
background.js
更改为
background.html
后,扩展不起作用呢。它应该可以工作,对吧?把“background.html”列为脚本是没有意义的,它只是一个页面。阅读背景页面文档:您可能需要执行
“Background”:{“scripts”:[“Background.js”]}
“Background”:{“page”:“Background.html”}
(其中html包含一组脚本标记),但不需要执行当前html页面作为脚本列出的混合操作。@phette23 ooh,谢谢你,伙计。现在我明白了。:)