我的扩展程序中有一个后台脚本,用于创建上下文菜单项并对其进行处理。单击它时,将创建包含特定详细信息的cookie。以下是该文件的来源:
function createC() {
var x = 1;
var y = 2;
//Create Cookie
document.cookie = document.URL + "=" + " " + x + " " + y + " ; " + 4102444799;
console.log("Cookie Created.");
}
chrome.contextMenus.create({
title: "Create Cookie",
contexts:["all"],
onclick: createC,
});
显然,其中使用的变量用于测试。当我在控制台中运行document.cookie;
时,cookie不会出现。我尝试过使用chrome.cookies API而且没有运气。
cookie是否因为在后台脚本中创建而不显示?
编辑:manifest.json
{
"manifest_version": 2,
"name": "MyExtension",
"description": "Do stuff",
"version": "0.1",
"icons": { "16": "icon.png",
"48": "icon.png",
"128": "icon.png" },
"options_page": "options.html",
"permissions": [
"tabs", "<all_urls>", "contextMenus", "cookies"
],
"background": {
"scripts": ["script.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["nav.js"]
}
]
}