访问Google Chrome扩展程序中的Cookie [英] Access cookies from Google Chrome extension

查看:154
本文介绍了访问Google Chrome扩展程序中的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何方法可以存取Chrome扩充功能的Cookie吗?
此代码

  document.cookie.length 

总是返回0。

解决方案

在这个网站上的东西真的错了。
从扩展程序获取实际的文档cookie是可能的。



你只需要这两个东西在你的清单:

 content_scripts:[
{
matches:[http:// * / * https:// * / *],
js:[cookie_handler.js]
}
],
permissions:[
tabs,
http:// * / *,
https:// * / *
],
pre>

您的cookie_handler.js将在每个加载器页面/框架/ iframe的相同上下文中执行。
尝试放一行:

  alert(document.cookie); 

,您会看到:)


Is there any way to access cookies from Chrome extension? this code

document.cookie.length

always returns - 0.

解决方案

It's the first time I read something really wrong on this site. Getting actual document cookies from an extension is INDEED possible.

you just need these two things in your manifest:

"content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["cookie_handler.js"]
    }
  ],
  "permissions": [
    "tabs",
    "http://*/*",
    "https://*/*"
  ],

your cookie_handler.js will be executed in the same context of every loader page/frame/iframe. try to put there a single line:

alert(document.cookie);

and you will see :)

这篇关于访问Google Chrome扩展程序中的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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