背景.html vs.背景.js - chrome扩展

background.html vs. background.js - chrome extension

本文关键字:背景 chrome 扩展 js html vs      更新时间:2023-09-26

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

我的情况:

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

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

where my content.js发送消息到后台并得到响应。到目前为止一切都很好!

但现在,而阅读文件为oauth,我很困惑不知道什么背景。html是。它实际上是应该包含我的背景。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.

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

您只允许指定一个脚本数组…

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

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

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

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

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

如果你试图同时指定这两个选项,扩展将无法加载:

的背景。页面和背景。脚本属性不能同时使用。无法载入舱单。