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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:11:27+00:00 2026-06-05T15:11:27+00:00

I am using the following code to access the background page function in google

  • 0

I am using the following code to access the background page function in google chrome

popup.html

function sendRequest(ea,eb)
{
console.log("Inside");
chrome.extension.sendRequest({ea:ea,eb:eb},
        function(response)
        {
            alert(response.farewell);

        });    
}

background.html

<html>
<body>
<script>
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
sendResponse({farewell: "goodbye"});
  })
</html>
</body>
</script>

manifest.json

{
  "name": "My First Extension",
  "version": "1.0",
  "manifest_version": 2,
  "background": {
    "page": "background.html"
  },
"content_scripts": [
    {
      "matches": ["http://*/"],

      "js": ["popup.js"]
    }
  ],



  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "mine.html"
  },
  "permissions": [
    "tabs","http://*/","background"

  ],
   "web_accessible_resources": ["loading.html","bu.png"] 


 }

However it does not print the alert. Can anyone tell me what i am doing wrong here?

  • 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-05T15:11:28+00:00Added an answer on June 5, 2026 at 3:11 pm

    Your HTML for background.html is extremely malformed and should be fixed;

    <html>
    <body>
    <script>
      chrome.extension.onRequest.addListener(
        function(request, sender, sendResponse) {
      sendResponse({farewell: "goodbye"});
        })
    </script>
    </body>
    </html>
    

    Tags should be closed in the reverse order of them being open to maintain a correct hierarchy. Since you had not done so, the <script> element was malformed and contained invalid syntax </html></body> so would not be executed correctly.

    Since you’re using version 2 of the manifest you may want to consider abstracting the contents of this script element (ignoring all HTML) to its own file (e.g. background.js) and change your manifest to the following;

    {
      "name": "My First Extension",
      "version": "1.0",
      "manifest_version": 2,
      "minimum_chrome_version": "18",
      "background": {
        "scripts": ["background.js"]
      },
    "content_scripts": [
        {
          "matches": ["http://*/"],
    
          "js": ["popup.js"]
        }
      ],
    
    
    
      "description": "The first extension that I made.",
      "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "mine.html"
      },
      "permissions": [
        "tabs","http://*/","background"
    
      ],
       "web_accessible_resources": ["loading.html","bu.png"] 
    
    
     }
    

    Notice that the background property now contains an array of strings representing JavaScript files to be loaded (in the order specified) in to a dynamically generated background page.

    I’ve also set the minimum_chrome_version property to 18 as manifest version 2 should only be used when targeting this version of Chrome and above.

    Developers should now only really need to use background pages instead of scripts when they need to support older versions of Chrome.

    Edit

    It just clicked that you’re attempting to execute embedded JavaScript within your background page. Manifest version 2 introduces Content Security Policies which prohibit the execution of inline (e.g. onclick="showDialog();" and href="javascript:void(0);") and embedded JavaScript. This is why your background.html won’t work and why background.js will. You will also want to ensure your popup.html doesn’t contain any embedded JavaScript. The best workaround (and generally best practice anyway) is to abstract all JavaScript into its own file (e.g. popup.js) which is referenced by the HTML file. For example;

    <script src="/popup.js"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code: function mymodule_menu_alter(&$items) { if (isset($items['node/add/page'])) { $items['node/add/page']['access arguments'] = FALSE;
I'm using the following code to access an HTML data attribute: HTML <p class=add-favorites-to-list>
I'm using the following code to access my DB using PHP <?php $host =
I am using the following code to access the list of users in my
I am using following code to create new wifi access point and to connect
In my iOS app, I get an access token using the following code: [self.facebook
I'm using pax-exam to load, activate and access osgi bundles. The following source code
I am using the following code to access a URL (the URL uses the
I am using the following code to access sdcard if mounted else using the
I am currently using the following code to access the property of an object

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.