background.html与background.js-chrome扩展 [英] background.html vs. background.js - chrome extension

查看:88
本文介绍了background.html与background.js-chrome扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am really confused here. I am trying to understand the file architecture of chrome extension. I am reading this doc: https://developer.chrome.com/extensions/overview#arch

我的情况:

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

I want to setup the oauth flow so that user can log in inside the extension (the other endpoint is my django backend). Till now, I have these files:

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

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

where my content.js sends message to background.js and gets response back. so far so fine!

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

But now while reading the doc for oauth, i am confused not knowing what the background.html is. is it actually the file which should contain all js code of my background.js? but, if i change this in manifest to .html, like:

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

扩展名不再起作用.在OAuth文档中,它表示:

extension isnot working anymore. In OAuth doc, it says:

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

what is the difference between background.html and background.js?

推荐答案

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

You're only allowed to specify either an array of scripts...

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

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

... or a page, which can then reference the script(s) the page needs:

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

从理论上讲,您的 background.html 页面除了需要的脚本列表之外,什么都不是.

Your background.html page could in theory be nothing else other than a list of needed scripts.

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

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

If you try to specify both, the extension won't load:

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

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

这篇关于background.html与background.js-chrome扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆