Cookie setting fails in background html when called at startup

I am trying to set a custom cookie in my chrome extension so that my server knows that the client is executing the extension.

I tried this approach:

chrome.cookies.set({ url: 'http://www.mydomain.com', name: 'iamalive', value: 'yes' }, function(cookie) { ... }); 

This works great when chrome is already loaded and running (for example: immediately after installation). but when this code works while chrome is running, I get this error:

Error during cookie.set: there is no cookie storage available for the current execution context.

Can I tell when the chrome.cookies API is ready? If not, is there another solution to the problem, for example, changing the user agent or adding a custom header to all HTTP requests to the server?

+4
source share

Source: https://habr.com/ru/post/1383431/


All Articles