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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:42:30+00:00 2026-05-24T11:42:30+00:00

I have written an extension in Google Chrome that opens a tab to a

  • 0

I have written an extension in Google Chrome that opens a tab to a webpage and injects code into that page. I have also registered a callback in chrome.tabs.executeScript to be called after the code’s completion. This callback then opens another tab to another page and performs other actions, but I don’t want that to happen until the first tab’s page has been manipulated.

My issue is that this callback is called when it should be called, but not when I want it to be called:

My injected code contains a setInterval that checks to see if certain DOM elements are present before acting on the page, and I don’t want the callback to activate until those DOM elements have been acted on.

I don’t know of any way to have the injected code interact with the code in my extension page.

Is there any way to tell the code in my extension page that it’s okay to keep going and call the callback at the right time?

Here’s some code that explains what I’m doing now:

function doStuffWithTabs() {
    chrome.tabs.create({url: 'some/url/here'}, function(tab) {
        chrome.tabs.executeScript(tab.id, code: "var interval = setInterval(function(){if(jQuery(domElement).length){clearInterval(interval);workMagic();}},1);"}, function(){
            goForthAndConquer();
        });
    }
}

workMagic() represents the code that manipulates the DOM of the opened tab and goForthAndConquer() is what I want to happen when the manipulation of the opened tab is complete.

Right now, as you can plainly see, the injected code just registers the setInterval and immediately calls the callback. Again, I want the callback to happen after workMagic().

  • 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-24T11:42:31+00:00Added an answer on May 24, 2026 at 11:42 am

    You need to do it in two steps.

    script.js:

    //I would ditch setInterval in favor of setTimeout
    var interval = setInterval(function(){
        if(jQuery(domElement).length){
            clearInterval(interval);
            workMagic();
        }
    },15); //15 is recommended minimum
    
    function workMagic() {
        //manipulate dom
        chrome.extension.sendRequest({action: "finished", other: "data"});
    }
    

    background.html:

    chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
        if (request.action === 'finished') {
            console.log("dom manipulation is finished in tab #", sender.tab.id);
            goForthAndConquer();
        }
    });
    
    function doStuffWithTabs() {
        chrome.tabs.create({url: 'some/url/here'}, function(tab) {
            chrome.tabs.executeScript(tab.id, {file: "script.js"});
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an extension for google chrome and I have a bug I
I've written a Google Chrome extension (https://chrome.google.com/webstore/detail/fhmcfamnddgoloojehbeokifhaiiebfm), and I'm noticing that the extension works
I have written a Chrome extension that adds a char counter to some input
I have written a very simple Chrome extension. It consists of this background page:
I have written a following code to get just the file name without extension
I have an MFC extension DLL that I've written. It contains derived classes of
I have written a ruby script which opens up dlink admin page in firefox
I have written some extension methods that extend the html helper class for client
I have written a Firefox extension that catches when a particular URL is entered
I'm refactoring some code and I have written a method that modifies a Dictionary

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.