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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:53:18+00:00 2026-06-17T03:53:18+00:00

I am quite confused about the what are counted as chrome extension view, which

  • 0

I am quite confused about the what are counted as chrome extension view, which directly linked to what function I can use for passing messages between different components.

Let me just describe what I am trying to do first;

My background.html creates Desktop Notifications based on some events received from a node.js server through socket.io.

When the user clicks on the notification, I want to create a new tab pointing to a html within my extension (/src/view/token.html), and then send some data from the background.js (where my socket.io codes are) to the new tab. And I want to do this through message passing.

So, basically, i am doing

 var notification = webkitNotifications.createNotification(image, title, content);
 notification.onclick(function(e){

    chrome.tabs.create({url: "/src/view/tokens.html"}, function(tab){
        //just to make sure the tab is activated..
        chrome.tabs.onUpdated.addListener(function(tabId){
            if(tabId == tab.id) {
                chrome.tabs.sendMessage({data: whatever_data}, tabId); 
            }
        });
    });

 });

Now my problem is in my tokens.js (loaded in tokens.html), I try to listen for the message using:

chrome.extension.onMessage.addListener(function (msg, _, sendResponse) {
console.log(msg);
});

but I am getting “Uncaught TypeError: Cannot read property ‘onMessage’ of undefined:, so I assume that I don’t have access to chrome.extension in the tokens.html???

I tried this with popup page (browser action popup) and option page, and they all worked just fine. So, I guess the view I created is just not a chrome extension page?

Now I am confused…
1) What are considered as chrome extension pages that have access to the chrome.* API
2) How should I implement what I want to do?

Thanks!

  • 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-17T03:53:20+00:00Added an answer on June 17, 2026 at 3:53 am

    Problems in your code

    • chrome.tabs.sendMessage() wrong Invocation pattern
    • As complete code is not shared, i assume permissions are given to all pages, because manifest don’t generate warnings for some set of values.
    • notification.onclick(function creates Uncaught TypeError: Property 'onclick' of object #<Notification> is not a function error

    Chrome.tabs.sendMessage

    Invocation form of chrome.tabs.sendMessage({data: whatever_data}, tabId); should be chrome.tabs.sendMessage(tabId,{“data”: “whatever_data”}); (Tab id followed by message).

    notification.onclick(function

    Use notification.onclick = (function( assign handler to onclick property (because it is not a function)

    After fixing above problems i got your script running.

    manifest.json

    Registered background scripts and given all permissions needed.

    {
        "name": "Message Passing",
        "description": "This is used as a message passing",
        "version": "1",
        "manifest_version": 2,
        "background": {
            "scripts": [
                "background.js"
            ]
        },
        "permissions": [
            "notifications",
            "tabs"
        ]
    }
    

    background.js

    Modified code to eliminate errors

    //Created Notification
    var notification = webkitNotifications.createNotification("icon.jpg", "title", "content");
    //Added onclick property
    notification.onclick = (function (e) {
        //Created new tab
        chrome.tabs.create({
            url: "/src/view/notification.html"
        }, function (tab) {
            //just to make sure the tab is activated..
            chrome.tabs.onUpdated.addListener(function (tabId) {
                if (tabId == tab.id) {
                    //Send Mesage
                    chrome.tabs.sendMessage(tabId, {
                        "data": "whatever_data"
                    });
                }
            });
        });
    });
    notification.show();
    

    notification.html

    Ensure there is no inline script or <script> tag to comply with CSP.

    <html>
    
        <head>
            <script src="notification.js">
    
            </script>
        </head>
    
        <body>
            <p>This is a notification</p>
        </body>
    
    </html>
    

    notification.js

    Used your script with no changes!

    chrome.extension.onMessage.addListener(function (msg, _, sendResponse) {
        console.log(JSON.stringify(msg));
    });
    

    Output

    You can see message(s) being received in your new tab.

    enter image description here

    References

    • CSP
    • Desktop Notifications
    • chrome.tabs.sendMesage
    • chrome.extension.onMesage
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a little confused about render, not quite sure which path it chooses to
I am quite confused about the type of the object which is rethrown in
I'm trying to find out more about MySQL VIEW's, and I'm still quite confused
I'm quite confused about the use of methods to manipulate a list in python.
I've been learning about the Model-View-Controller paradigm (MVC), but I'm quite confused since some
I am quite confused about the difference between an index on table and index
I am still quite confused about NHibernate schema export and creation. What I want
I'm new to SVN and I'm quite confused about a problem. I am using
I read Scott Meyers' article on the subject and quite confused about what he
I am quite confused with how to effectively use the Html.DropDownList helper for ASP.NET

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.