Chrome扩展是否有自己的document.cookie? [英] Does chrome extension has it's own document.cookie?

查看:129
本文介绍了Chrome扩展是否有自己的document.cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Chrome扩展。我想在浏览器cookie中存储一些数据,以便以后使用它。 Cookie是完美的方式。对于所有网站,Chrome扩展是否拥有自己的文档cookie?



当我做了一些研究 https ://developer.chrome.com/extensions/cookies
但它主要是谈论cookie API和获取其他网站的cookies因此是个问题。此外,铬存储与使用cookie有什么优势?我只需要存储2/3个键值对。 https://developer.chrome.com/apps/storage


我会说只有一行,你会理解它。 > Cookies总是与网站/域相关。


询问Chrome扩展程序是否有Cookie是没有意义的。您可以为每个域名拥有一个cookie。



更多信息可帮助您解决问题。如果您看到Chrome扩展模型,您可以看到有


  1. 后台脚本

  2. 内容脚本

  3. 弹出页面/脚本

如果要将cookie存储在后台脚本/ ,那么你一定可以做到。但是,该cookie将保存在您的后台脚本的域中,该域本质上就是您的Chrome浏览器扩展名。



如果您将cookie存储在内容脚本中,那么您正在存储信息在Cookie中属于您的内容脚本注入的域。


I'm writing a chrome extension. I want to store some data in the browser cookie so that I can use it later. Cookie is a perfect way to do that. Does chrome extension have it's own document cookie for this like all the websites?

I got this result when I did some research https://developer.chrome.com/extensions/cookies But it mostly talks about cookie API and getting cookies of other websites hence the question. Also does chrome storage have any advantages over using a cookie? I just need to store 2/3 key value pairs. https://developer.chrome.com/apps/storage

解决方案

I will say Just one line and you will understand it.

Cookies are always related to a website/domain.

It does not make sense to ask if Chrome extension has a cookie. You can have a cookie for every domain.

Some more information to help you solve your problem. If you see chrome extension model, you can see there are

  1. Background Scripts
  2. Content Scripts
  3. Popup Page/Scripts

If you want to store cookie in a background script/ popup script, then you can definitely do it. But that cookie will be saved for the domain of your background script which is essentially your chrome extension id.

If you store cookie in a content script, then you are storing information in cookie which belongs to the domain on which your content script is injected.

这篇关于Chrome扩展是否有自己的document.cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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