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

The Archive Base Latest Questions

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

In my extension, I send some injection code when the current tab url is

  • 0

In my extension, I send some injection code when the current tab url is in the list of my target urls. here is the code

chrome.tabs.onUpdated.addListener(function(tabId, info) {
if(info.status == "complete") {
var tabUrl = "";
var run = false;
chrome.tabs.get(tabId, function(tab) {
    tabUrl = tab.url;
});
var storedList = localStorage["GAR_ExcList"];
if(!storedList) storedList = "";
var storedListArray = storedList.split("\n");
for(var i = 0; i < storedListArray.length; i++) {
    var ind = tabUrl.indexOf(storedListArray[i]);
    alert("for " + i + " index is " + ind);
    if(ind != -1) {
    alert("Running");
    run = true;
    break;
    }
}

if(run) {
    chrome.tabs.executeScript(tabId, { file: "js/jquery-1.6.1.min.js" }, function() {
    chrome.tabs.executeScript(tabId, { file: "js/inject.js"});
    });
}
else {
    alert("excluding");
}
}});

Even though this code perfectly well. For some reason, when I comment out the alert within the for loop, I get run = false and I receive the last alert, which I should not.

Has anyone ever seen something like this before? Any help is very much appreciated.

Best,

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

    Instead of:

    chrome.tabs.onUpdated.addListener(function(tabId, info) {
        ...
        var tabUrl = "";
        chrome.tabs.get(tabId, function(tab) {
            tabUrl = tab.url;
        });
    

    Try:

    chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
        ...
        var tabUrl = tab.url;
    

    chrome.tabs.get() is asynchronous, so you need to put the rest of the code inside its callback if you use this approach.

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

Sidebar

Related Questions

I am trying to create Google Chrome extension that will send interesting links to
i am beginner with chrome extension.There is simple problem. There is the code in
I want to inject some HTML into some websites with a Chrome extension, and
I'm building a small Chrome extension that must send messages through a POST http
I am building my first chrome extension, for that I want to have some
I'm looking for a PHP extension that allows me to connect, bind/listen, send, and
My extension is an overlay that has some images inside a toolbar. I need
An extension of my previous thread here . I'm launching embedded resource applications via
I compiled a PHP extension on Fedora Core 12, but when I send it
I'm debugging my webserver, and I'd like to manually send HEAD requests to some

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.