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 7918809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:38:02+00:00 2026-06-03T15:38:02+00:00

As usual, I have Googled this a fair bit and read up on the

  • 0

As usual, I have Googled this a fair bit and read up on the Message Passing API, but, again, I’ve had to resort to the good fellas at StackOverflow.

My question is this: When passing messages between a Google Chrome extension’s background page and content script, is there any way to make it asynchronous – that is, to delay the JavaScript until the messages are detected as being successfully being passed?

I have a function immediately after the message-passing function makes use of the localStorage data that is passed. On first runs the script always results in an error, due to the data not being passed fast enough.

Currently, I’m circumventing this with setTimeout(nextFunction, 250); but that’s hardly an elegant or practical solution, as the amount and size of the values passed is always going to change and I have no way of knowing how long it needs to pass the values. Plus, I would imagine, that passing times are relative to the browser version and the user’s system.

In short, I need it to be dynamic.

I have considered something like

function passMessages(){
    chrome.extension.sendRequest({method: "methodName"}, function(response) {
        localStorage["lsName"] = response.data;
    });

    checkPassedMessages();
}

function checkPassedMessages(){
    if (!localStorage["lsName"]){
        setTimeout(checkPassedMessages, 100); //Recheck until data exists
    } else {
         continueOn();
    }
}

but I need to pass quite a lot of data (at least 20 values) and, frankly, it’s not practical to !localStorage["lsName1"] && !localStorage["lsName2"] etc etc. Plus I don’t even know if that would work or not.

Does anyone have any ideas?

Thanks

Update: Still no answer, unfortunately. Can anyone offer any help at all? :/

  • 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-06-03T15:38:04+00:00Added an answer on June 3, 2026 at 3:38 pm

    I don’t know whether I’m interpreting your question wrong. As far as I understand you are sending request from your extension page to a content script. The request handler in the content handler does some operation on the message passed after which you need the control back in the extension page. If this is what you need you have everything in the Google Extension Documentation. The following code works

    //Passing the message
    function passMessages(){
      chrome.extension.sendRequest({method: "methodName"}, function(response) {
        //callback function that will be called from the receiving end
    
        continueOn();
      });
    }
    
    //Recieving the message
    chrome.extension.onRequest.addListener(
      function(request, sender, sendResponse) {
         //Do the required operation with the message passed and call sendResponse
    
         sendResponse();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As usual, I've Googled this and read through the documentation ( W3C's CSS Selectors
I have the following code and it's working (as usual) in everything but IE.
I have tried the usual suspects to try and get this to work. zoom:1,
I have the usual google maps api startup code: function initialize() { var mapOptions
Does anyone have a clue how to use this? The documentation as usual is
I have been looking around but I have not found a problem like this.
Have any of you had this problem before? I'm trying to obfuscate a solution
I have a usual login form consisting of two input fields, one for login,
I have a usual editButtonItem in my navigationBar (created by the system), and I'd
I have a problem with Ebean. I have the usual Objects PsecUser, PsecRoles and

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.