Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't pass parent function argument to child anonymous function
    primarykey
    data
    text
    <p>In one of the background files of my chrome extension I'm checking for cookies and ran into a problem. In my function <code>chrome.cookies.get({"url": domain, "name": name},function(cookie) {});</code> I am able to get the cookie object and pass it into the last parameter (an anonymous function) as the variable <em>cookie</em> and access it's value with <em>cookie.value</em>.</p> <p>The problem is that I am only able to send a return response from the parent function and not the nested anonymous function from within the <code>chrome.cookies.get</code> call.</p> <p>In my example below I am able to return a response (verified with an alert on another page) with <strong>value1</strong> but <strong>value2</strong> is never being returned... After doing a lot of reading I think I narrowed down the problem to a scoping error... By that I mean my response call <strong>sendResponse</strong> (a parameter in the parent function) is not being accessed by the nested anonymous function.</p> <pre><code>function getCookies(request, sender, sendResponse, domain, name) { chrome.cookies.get({"url": domain, "name": name}, function(cookie) { sendResponse({"myvar":"value2"}); //DOES NOT WORK if(cookie){ anotherFunction(cookie.value); }else{ anotherFunction("0"); } }); sendResponse({"myvar":"value1"}); // WORKS } </code></pre> <p>So basically, I just need to figure out some method to push my <strong>sendResponse</strong> parameter down to the anonymous function; or re-create a similar method that would not cause this scoping issue. Any assistance or guidance with this issue would be greatly appreciated. Thank you in advance for your time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload