在firefox扩展中无法获取http://127.0.0.1:3000/的cookie

问题描述 投票:0回答:1

我的扩展程序没有从 Firefox 上的 Ruby on Rails 开发网站获得任何 Cookie。我已将扩展程序的 ID 添加到我的 CORS 策略中。

main.js

browser.cookies.getAll({ url: "http://127.0.0.1:3000" }).then(console.log, console.error)

manifest.json

{
  "manifest_version": 2,
  "name": "Example Name",
  "version": "1.0",
  "description": "Description",
  "permissions": [
    "cookies",
    "*://127.0.0.1:3000/*"
  ],
  "background": {
    "scripts": [
      "main.js"
    ]
  }
}

饼干 screenshot of localhost's cookies

输出:

[]

javascript firefox-addon
1个回答
0
投票

当您加载扩展时,根据您指定的清单,您应该收到一条警告,指出主机权限必须与(过时的)正则表达式匹配:

^(https?|wss?|file|ftp|\*):\/\/(\*|\*\.[^*/]+|[^*/]+)\/.*$/

(这是一条过时的消息,因为 ftp 已经有一段时间不支持了。它也可能存在其他问题。)由于主机权限请求与模式不匹配,因此该权限请求将被忽略。换句话说,不包括端口。

  ...
  "permissions": [
    "cookies",
    "*://127.0.0.1/*"
  ],
  ...

类似地,从详细信息对象中的

url
值中删除端口。详细信息对象旨在过滤 cookie 存储中的 cookie。我还建议向详细信息对象添加一些值,以确保您不会排除商店中可能匹配的 cookie。

browser.cookies.getAll( {
  firstPartyDomain: null,
  partitionKey: {},
  url: "http://127.0.0.1/*"
} ).then( console.log, console.error );

请注意:

  1. “127.0.0.1”必须是要匹配的主机名。如果您在 URL 栏中使用“localhost”,它将不匹配(这可能适合测试);和
  2. getAll
    调用仅获取默认存储中的“所有”cookie(“firefox-default”,即不是私有窗口,也不是上下文身份)。
© www.soinside.com 2019 - 2024. All rights reserved.