我的扩展程序没有从 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"
]
}
}
输出:
[]
当您加载扩展时,根据您指定的清单,您应该收到一条警告,指出主机权限必须与(过时的)正则表达式匹配:
^(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 );
请注意:
getAll
调用仅获取默认存储中的“所有”cookie(“firefox-default”,即不是私有窗口,也不是上下文身份)。