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

标签 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 代码的文件吗?但是,如果我在 list 中将其更改为 .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.

但是在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 有什么区别?

最佳答案

您只能指定其中一个脚本数组...

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

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

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

您的 background.html 页面在理论上可以只是所需脚本的列表。

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

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

The background.page and background.scripts properties cannot be used at the same time. Could not load manifest.

关于javascript - background.html 与 background.js - chrome 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24978473/

相关文章:

javascript - .addHitRegion() 在 Chrome 中不起作用

javascript - 如何使用 javascript 每天更改文本内容?

html - CSS/HTML 如何在 html 中保留文本格式

html - Bootstrap 控制列的堆叠方式

google-maps - Chrome navigator.geolocation.getCurrentPosition()错误403

javascript - 为什么我的 WebGl 帧率在 Chrome 中缓慢下降?

javascript - 运行时代码编译

javascript - 如何更改类onclick?

javascript - 我怎么知道光标现在焦点在输入或文本区域或选择

html - 悬停时更改标签和输入元素的字体大小 - 使用 CSS 的 HTML