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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:37:20+00:00 2026-05-28T19:37:20+00:00

Im trying to have my code to be injected using the content script method

  • 0

Im trying to have my code to be injected using the content script method for google chrome extensions. This only works when my manifest does not have a Popup page and my background.html has this:

chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, { file: "jquery.js" }, function() {
chrome.tabs.executeScript(null, { file: "content_script.js" });
});
});

How can I have this code be triggered every time a new page has been loaded in chrome while having a PoPup page? because so far the only way that it works is when I click the browser action button of the extension.

Also in my content script section of manifest I have included all this:

"content_scripts": [
{

"matches": ["http://jquery.com/*"],
"all_frames":true,
  "js": ["jquery.js","jquery-ui.min.js","content_script.js"],
   "run_at": "document_end"
}
],  
  • 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-28T19:37:21+00:00Added an answer on May 28, 2026 at 7:37 pm

    Short answer: Use chrome.tabs.onUpdated.addListener instead of chrome.browserAction.onClicked.addListener from the background page to load the content script every time the page is updated.

    Long answer: You CAN in fact have a content script be loaded when their is a popup page, either by including the content script from the manifest or using programmatic injection from the background page (as you suggested in your question).

    From the manifest:

    {
      "name": "My extension",
      ...
      "content_scripts": [
        {
          "matches": ["http://myurl.com/*"],
          "css": ["mystyles.css"],
          "js": ["jquery.js", "myscript.js"]
        }
      ],
      "permissions": [
         "http://myurl.com/*",
         "tabs"
      ],
      "background_page": "background.html",
      "browser_action": {
         "popup": "popup.html"
      }
      ...
    }
    

    Make sure the “matches” property matches the URL for the page you want to load the content script on.

    Using programmatic injection:

    You can use the way you suggested in your question, which will insert the content script when the browser action is clicked OR you could do it every time the browser URL is updated like so:

    chrome.tabs.onUpdated.addListener(function() {
      chrome.tabs.executeScript(null, { file: "jquery.js" }, function() {
        chrome.tabs.executeScript(null, { file: "content_script.js" });
      });   
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my ASP.NET application written in C# that is trying
I'm extremely new to JS and have this code that I'm trying to tweak.
I am trying to compare two dates. I have this code which I thought
I'm trying to have adsense javascript code added to a designated div location using
In a CUDA kernel, I have code similar to the following. I am trying
I've been trying to implement unit testing and currently have some code that does
I'm trying to use opengl in C#. I have following code which fails with
I’m trying to issue web requests asynchronously. I have my code working fine except
I have been trying to find a code snippet to do an unsharp mask
I have been trying to learn how to add testing to existing code --

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.