【问题标题】:Getting undefined for chrome cookie get in chrome extension在 chrome 扩展中获取未定义的 chrome cookie
【发布时间】:2018-01-11 05:05:34
【问题描述】:

我正在尝试使用 chrome.cookies.get 函数根据传递的域检索 cookie,但出现以下错误。有没有人遇到过同样的问题?请指教。

Actual CODE:

function getCookies(domain, name, callback) {
    chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
        if(callback) {
            callback(cookie.value);
        }
    });
}

ERROR:

index.js:167 Uncaught (in promise) TypeError: Cannot read property 'get' of undefined
    at getCookies (index.js:167)

【问题讨论】:

  • 谢谢@DashWinterson
  • @DashWinterson 当我查找 chrome 变量值时,我只看到这个,{loadTimes: ƒ, csi: ƒ, app: undefined, extension: undefined, i18n: undefined, ...} 我有什么遗漏吗?请指教。

标签: cookies google-chrome-extension


【解决方案1】:

Content scripts cannot Use chrome.* API,但 chrome.extension 的某些部分。您可以在一些 backgorund 脚本中使用 chrome.cookies.get 并根据需要使用 cookie。

但是,在内容脚本中,您可以使用“document.cookie”来获取脚本 here 的 cookie。

Here是内容脚本的官方文档。

如果您遇到的问题不仅仅是阅读 cookie,请在问题中提及,以便我们为您提供帮助。

【讨论】:

  • 我能够使用后台脚本来实现它,因为就像你说的内容脚本使用 chrome.cookie 辅助方法有一些挑战。谢谢:)
猜你喜欢
  • 2022-07-21
  • 1970-01-01
  • 2012-09-03
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多