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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:32:28+00:00 2026-05-27T04:32:28+00:00

I have the latest Chrome, I’m building an extension. Consider the following code: var

  • 0

I have the latest Chrome, I’m building an extension.

Consider the following code:

var returnTab = false; // init the variable as false

var createNewTab = function(){
returnTab = false; // make sure we start with this var as false

chrome.tabs.create({url:'http://www.google.com/'}, function(tab){
    returnTab = tab; // put the returntab object inside the variable
});

while(returntab===false){  }; // wait for the tab to be created.
return returnTab;
};
c = createNewTab();

All fine and it should work; except it doesn’t. The createNewTab() function gets stuck into an infinite loop and the variable returnTab never gets the callback return value.
If I do it the way I’m meant to do it, without the wait loop everything works and the callback function executes the way it should.

Why isn’t this working?

LE: Looks like the callback function waits for the loop to complete. Does anyone know a way to keep the whole function busy until the callback function fires up?

  • 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-27T04:32:28+00:00Added an answer on May 27, 2026 at 4:32 am

    Just guessing here, as I have no actual experience making Chrome extensions, but maybe the while() loop is hogging the thread and never really allowing the callback you specified in the call to create() to ever run. That’s what would happen if you did this in a regular website.

    Try adding a setTimeout() call to the waiting loop, so that, while it waits, it doesn’t use any CPU, instead of using 100% of it… I’m not sure how you can do this in the context of your extension, the code you showed doesn’t quite have enough context.

    If I were doing this, however, instead of looping and waiting, i’d just add whatever you want to do once the tab is created in the callback function (right where you are setting returnTab). That’s the normal way of doing stuff in JS…

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

Sidebar

Related Questions

So im building a chrome extension and I have placed an audio flash player
I have the latest version of Firefox (4 beta) and Chrome. I would like
I have weird problem with this code $('img').hover(function(){ var $cap = $(this).parent().find('.cap'); window.setTimeout(function(){$cap.stop(true,false).animate({bottom:164},500)},500); },function(){
I have this code in an HTML page: alert(JSON.stringify(new Date())); I'm including the latest
I have the following code to load jQuery in a document from a certain
The code bellow works well with latest version of Chrome on Linux and Windows,
I have the latest ReSharper 5.0 build (1655), where I have encountered the suggestion
I'm running Windows XP SP3 and I do have the latest .NET libraries installed,
I have updated to latest Django version 1.0.2 after uninstalling my old Django version.But
I have downloaded the latest build of pyscopg2 and have tried to build 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.