Пишу расширение, нужно получить куки определенного сайта на любой вкладке
manifest.json
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions": [
"activeTab",
"tabs",
"cookies",
"storage",
"<all_urls>"
],
"content_scripts": [
{
"matches": [
"http://*/*", "https://*/*"
],
"js": [ "jquery.min.js", "bundle/content.js", "bundle/event.js"],
"run_at": "document_start"
}
],
"web_accessible_resources":[
"main.js",
"background.js",
"*.svg",
"*.ttf",
"img/*"
]
в
background.js
пробовал через executeScript, получаю ошибку Cannot read property 'executeScript' of undefined:
chrome.tabs.executeScript({
code: 'performance.getEntriesByType("resource").map(e => e.name)',
}, data => {
if (chrome.runtime.lastError || !data || !data[0]) return;
const urls = data[0].map(url => url.split(/[#?]/)[0]);
const uniqueUrls = [...new Set(urls).values()].filter(Boolean);
Promise.all(
uniqueUrls.map(url =>
new Promise(resolve => {
chrome.cookies.getAll({url}, resolve);
})
)
).then(results => {
// convert the array of arrays into a deduplicated flat array of cookies
const cookies = [
...new Map(
[].concat(...results)
.map(c => [JSON.stringify(c), c])
).values()
];
// do something with the cookies here
console.log(uniqueUrls, cookies);
});
});
пробовал через
chrome.cookies.get
chrome.cookies.get({url: "
test.test.com", name: 'site_session'}, function(session) {
console.log(session)
});
ошибка Uncaught TypeError: Cannot read property 'get' of undefined