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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:14:39+00:00 2026-05-28T05:14:39+00:00

I have the following code in my background script: chrome.tabs.onUpdated.addListener(function(tabId, changeinfo, tab) { if

  • 0

I have the following code in my background script:

chrome.tabs.onUpdated.addListener(function(tabId, changeinfo, tab) {
    if (changeinfo.status !== 'complete')
        return;

    if (!matchesUrlFilters(tab.url))
        return;

    chrome.tabs.executeScript(tabId, { file: "jquery-1.7.1.min.js" }, function() {
        chrome.tabs.executeScript(tabId, { file: "enhance.js" });
    });
});

However, this seems to inject my content script twice in some cases (it might happen when enhance.js does window.history.pushState).

How can I fInd out whether the tab already has my content script? I tried chrome.tabs.sendRequest but it never called the callback if the content script was not yet added.

  • 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-28T05:14:39+00:00Added an answer on May 28, 2026 at 5:14 am

    EDIT: Updated per first comment on this answer.

    You might try something like this. Add a onRequest listener that will be used as a callback to load the scripts you want, but they will only load based on a value sent as part of the request message. Then use executeScript to call “code” directly that sends a message with the value of a global variable (if it exists).

    chrome.tabs.onUpdated.addListener(function(tabId, changeinfo, tab) {
        ...
    
        // execute a content script that immediately sends back a message 
        // that checks for the value of a global variable which is set when
        // the library has been loaded
        chrome.tabs.executeScript(tabId, {
            code: "chrome.extension.sendRequest({ loaded: EnhanceLibIsLoaded || false });"
        });
    
        ...
    });
    
    // listen for requests
    chrome.extension.onRequest.addListener(function(req, sender, sendResponse) {
        if (req.loaded === false) {
            chrome.tabs.executeScript(tabId, { file: "jquery-1.7.1.min.js" }, function() {
                chrome.tabs.executeScript(tabId, { file: "enhance.js" }, function() {
                    // set the global variable that the scripts have been loaded
                    // this could also be set as part of the enhance.js lib
                    chrome.tabs.executeScript(tabId, { code: "var EnhanceLibIsLoaded = true;" });
                });
            });
         }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to trigger the click, to which following code is listening: chrome.browserAction.onClicked.addListener(function(tab) {});
I have the following code <HTML> <HEAD> <style type=text/css> .setbgcolor{ background-color:blue; } </style> <script
i have the following simple code, but it doesn,t work <ul> <li id=one onmouseover=this.style.background-color='white';>
I have the following HTML: <h2>Embed Code</h2> <pre> <code> &lt;script type=&quot;text/javascript&quot;&gt; var something =
I have the following code in JQuery (JavaScript), and works fine in Chrome, Safari
I have the following code: <html> <head> <script type=text/javascript language=javascript src=jquery/jquery-1.5.1.js></script> <script type=text/javascript language=javascript
I have the following HTML code: <script src=http://code.jquery.com/jquery-1.6.2.min.js></script> <div id=A style=width:100px; height: 100px; background:
I have the following code: <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js></script> <script> $(document).ready(function() { // hides
I have the following JavaScript code: function createNotification(title, body, canDismiss, callback) { //create the
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.