Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:59:06+00:00 2026-05-24T22:59:06+00:00

I have a chrome extension, with a javascript file that gets executed. The javascript

  • 0

I have a chrome extension, with a javascript file that gets executed. The javascript file makes this call to background.html:

action.js

var action = "";
chrome.extension.sendRequest({method: "getLocalStorage", key: "action"},
  function(response) {
     alert(response.data);
     action = response.data;
 });
alert('action:'+action);

and in background.html:

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getLocalStorage")
  sendResponse({data: localStorage[request.key]});
else
  sendResponse({});

The behavior that i get is an alert box saying “action:” and then an alert box saying “video” which is the correct value for action.

Why are these alert boxes showing out of order, and why isn’t the variable action getting the response.data value? Does it have to do with a delay from the sendRequest method? How can I make the script wait, so that I can get the value? (I’m going to need to do this request multiple times – I have 4 values that I need to request)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:59:08+00:00Added an answer on May 24, 2026 at 10:59 pm

    I assume sendRequest is an asynchronous method (much like an Ajax call). The script does not halt and wait for the response.

    The only solution is to call the other functions which need the response inside the callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple Chrome extension. It consists of this background page:
I started making this simple google chrome extension in javascript. And in the beginning
I have a chrome extension that very simply injects CSS before a page loads.
I have a simple Chrome extension that uses the content script feature to modify
I have this Chrome Extension, it adds a poke all button under your pokes.
I'm trying to make a google chrome extension using javascript/html. Currently, I'm simply trying
I have a javascript script in a chrome extension i'm building. It is content
I'm trying to write a Chrome Extension that just adds a CSS file to
I have a firefox extension and I loaded an external javascript file to access
I have a chrome extension. The extension page has iframe that loads server, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.