首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >background.html与background.js -铬扩展

background.html与background.js -铬扩展
EN

Stack Overflow用户
提问于 2014-07-27 06:26:13
回答 1查看 17.7K关注 0票数 16

我真的很困惑。我正在努力理解铬扩展名的文件架构。我正在读这个医生:https://developer.chrome.com/extensions/overview#arch

我的处境:

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

代码语言:javascript
复制
background.js 
content.js
popup.html
manifest.json

其中,我的content.js向background.js发送消息并获得响应。到目前为止还不错!

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

代码语言:javascript
复制
"background": {
"persistent": false,
"scripts": ["jquery111.js", "background.html"]

扩展不再起作用了。在OAuth文档中,它说:

代码语言:javascript
复制
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.

但在架构文档中,它说:

代码语言:javascript
复制
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有什么区别?

EN

回答 1

Stack Overflow用户

发布于 2019-05-09 14:29:14

你只能指定一组脚本.

代码语言:javascript
复制
"background": {
    "persistent": false,
    "scripts": [ "jquery111.js"]
}

..。或者一个页面,然后该页可以引用页面所需的脚本:

代码语言:javascript
复制
"background": {
    "persistent": false,
    "page": "background.html"
}

理论上,您的background.html页面只能是一个需要脚本的列表。

代码语言:javascript
复制
<script src="jquery111.js"></script>

如果尝试同时指定这两种情况,则扩展将不会加载:

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

票数 28
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24978473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档