Skip to content
Advertisement

Getting cookies in a google chrome extension [duplicate]

I am trying to get a cookie specifically from a domain using this code:

JavaScript

The problem is that the alert always says undefined. However, if I change

JavaScript

to

JavaScript

it works properly. How do I save the value to use later?

Update: It appears that if I call alert(ID) from the chrome console after the script runs, it works. How can I set my code to wait until chrome.cookies.get finishes running?

Advertisement

Answer

Almost all Chrome API calls are asynchronous, so you need to use callbacks to run code in order:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement