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

  • SEARCH
  • Home
  • 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 1004021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:04:04+00:00 2026-05-16T08:04:04+00:00

Having a problem while passing messages using content scripts in Google chrome extension dev

  • 0

Having a problem while passing messages using content scripts in Google chrome extension dev
My Code structure looks like this:

popup.html:

var oList;
function getHTML()
{
    chrome.tabs.getSelected(null, function(tab) {
     chrome.tabs.sendRequest(tab.id, {action:"getHTML"}, function handler(response) {
      oList = response.dom;
     });
   });

   alert("oList = "+oList );
}

and my content Script looks like this:

chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
  if(request.action == "getHTML"){
   sendResponse({dom: document.getElementsByTagName("HTML").length});   
     }
  });

When I debug my code by putting a breakpoint at “oList = response.dom;” in my popup.html, i get the
right value set from the content script. But while executing the extension, the “alert("oList = "+oList );” code
from the popup.html seems to be executing first before it goes to the server.. And therefore, its value is
not being set.. Can somebody tell me if I am wrong somewhere ?

  • 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-16T08:04:05+00:00Added an answer on May 16, 2026 at 8:04 am

    Most Chrome API methods are asynchronous. It means that when you are calling them the script doesn’t wait for their response and simply continues executing. If you want to execute something on response you should put it inside callback function:

    chrome.tabs.getSelected(null, function(tab) {
     chrome.tabs.sendRequest(tab.id, {action:"getHTML"}, function handler(response) {
      oList = response.dom;
      alert("oList = "+oList );
     });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an odd problem while deploying a Django site using Fabric. I've configured
as the title says I'm having the problem with content getting hidden while scrolling/dragging
I have a flash file menu i am having problem while link it to
Having a problem while deserializing a number of objects stored as BLOBs in a
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
I've been having this problem for a while and it's driving me nuts. I'm
I'm having a problem with scala generics. While the first function I defined here
While trying to troubleshoot a problem I'm having with a project, I noticed that
I am having problems while saving a pre-persisted JDO object in google-app-engine data store.
Is this code possible? A stupid question but I am having a problem understanding

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.