I am trying to insert cookies into chrome using a extension.
using this code (background.js) :
for (var i in request.cookies) {
var cookie = request.cookies[i];
console.log("request.cookies.url :" + request.cookies[i].url);
chrome.cookies.set( cookie, function(state) {
console.log("JSON.stringify(cookie) : " + JSON.stringify(state));
console.log(" chrome.extension.lastError : " + chrome.extension.lastError);
console.log(" chrome.runtime.lastError : " + chrome.runtime.lastError);
if (!state || state == null) {
console.log("cookies are not inserted " + chrome.runtime.lastError);
}
});
I have few queries. I am inserting two cookies, iteration is fine , as the debug log is showing two urls as i have shown below.
1) Does the cookie is set immediately...? Because my debug log shows this .
[17040:42156:0130/012610:INFO:CONSOLE(70)] "request.cookies.url :: http://fb.com/apps", source: chrome-extension://hdkkhahdmcfhgmfhhomnjlhahnghgjmp/background.js (70)
[17040:42156:0130/012610:INFO:CONSOLE(70)] "request.cookies.url :: https://fb.com/", source: chrome-extension://hdkkhahdmcfhgmfhhomnjlhahnghgjmp/background.js (70)
[17040:42156:0130/012610:INFO:CONSOLE(72)] "JSON.stringify(cookie) : undefined", source: chrome-extension://hdkkhahdmcfhgmfhhomnjlhahnghgjmp/background.js (72)
[17040:42156:0130/012610:INFO:CONSOLE(73)] " chrome.extension.lastError : undefined", source: chrome-extension://hdkkhahdmcfhgmfhhomnjlhahnghgjmp/background.js (73)
[17040:42156:0130/012610:INFO:CONSOLE(74)] " chrome.runtime.lastError : undefined", source: chrome-extension://hdkkhahdmcfhgmfhhomnjlhahnghgjmp/background.js (74)
[17040:42156:0130/012610:INFO:CONSOLE(76)] "cookies are not inserted undefined", source: chrome-extension://hdkkhahdmcfhgmfhhomnjlhahnghgjmp/background.js (76)
2) Will this undefined turn into cookie/ or these cookies will only reflect when I traverse to the URL specified into the cookie. Right now I am injecting the cookies as soon as the chrome opens on the default page. Will it make any effect. ?
Aucun commentaire:
Enregistrer un commentaire