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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:04:35+00:00 2026-06-05T12:04:35+00:00

In my Google Chrome extension, I have a content_script that I want to communicate

  • 0

In my Google Chrome extension, I have a content_script that I want to communicate with my background_page. Does anyone know how this can be done?

I have found a couple tutorials going over how a background page can communicate with a content_script but, as I have stated, I need the opposite to occur.

I want to run an automated script to clear my cache every 24 hours. I cannot do this from a content_script, I have to do this from the background page. The only way I can get this to work right now is if I tie in a “button” but as I said before, I want it automated to run every 24 hours.

BTW- I am already aware that Content Scripts cannot:
Use chrome.* APIs (except for parts of chrome.extension)
Use variables or functions defined by their extension’s pages
Use variables or functions defined by web pages or by other content scripts

As you can see the first item listed there is: chrome APIs, but I need to use a chrome API in my content_script, so hopefully someone has a work around. Please let me know.

  • 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-06-05T12:04:36+00:00Added an answer on June 5, 2026 at 12:04 pm

    Message Passing Doc from Google

    Content script:

    chrome.extension.sendRequest({greeting: "hello"}, function(response) { //request
      console.log(response.farewell);           //receive response
    });
    

    Background page:

    chrome.extension.onRequest.addListener(     //listen to requests
      function(request, sender, sendResponse) {
        console.log(sender.tab ?
                    "from a content script:" + sender.tab.url :
                    "from the extension");
        if (request.greeting == "hello")
          sendResponse({farewell: "goodbye"});  //send response
      });
    

    Also you can open up a Long-lived connection between content scripts and background page:
    http://code.google.com/chrome/extensions/messaging.html#connect

    contentscript.js
    ================
    var port = chrome.extension.connect({name: "knockknock"});
    port.postMessage({joke: "Knock knock"});
    port.onMessage.addListener(function(msg) {
          if (msg.question == "Who's there?")
        port.postMessage({answer: "Madame"});
      else if (msg.question == "Madame who?")
        port.postMessage({answer: "Madame... Bovary"});
    });
    
    
    background.html
    ===============
    chrome.extension.onConnect.addListener(function(port) {
      console.assert(port.name == "knockknock");
      port.onMessage.addListener(function(msg) {
        if (msg.joke == "Knock knock")
          port.postMessage({question: "Who's there?"});
        else if (msg.answer == "Madame")
          port.postMessage({question: "Madame who?"});
        else if (msg.answer == "Madame... Bovary")
          port.postMessage({question: "I don't get it."});
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a Google chrome extension so that I can highlight text
While creating a Google Chrome extension, I have code that must remain in a
I have a Google Chrome extension that upon pressing a button executes an xmlhttp
I'm building this Google Chrome extension and I find it a nuisance to have
I have created a simple Google chrome extension that overrides CSS classes using the
I have a Google Chrome extension that opens a Twitter Bootstrap dialog (using JQuery
I am making a Google Chrome extension and I would like to have my
At the moment I am developing a Google Chrome Extension in which I have
I am working on creating a Google Chrome extension. We have it included in
I am trying to create Google Chrome extension that will send interesting links to

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.