JavaScript Getting my head wrapped around Chrome app and extension messaging with specific setup getting my head wrapped around

I'm trying to build a sample extension that can field incoming messages from a serial device connected to the computer and have that affect an on screen UI element.
enter image description here

For example. Lets say the extension is a running tally of total images encountered while browsing pages. The extension shows a little box in the top right that just keeps count of images encountered. So with each tab I open or each page i navigate to, the extension box (not a pop up but appears as an overlay on every page) has a number that just keeps increasing. The extension has a background.js script used to listen to external messages coming from the chrome serial app and then relays that information to the content script.

Then I have a serial device connected via usb to the computer. I am using this guy's chrome serial app to read in some serial numbers that are coming in. I want these numbers to decrement the total in the extension UI image counter, for example.

I've read through the Chrome messaging api and thought I could figure out how to send these messages between the chrome app and the chrome extension.
Placed the following in Chrome Serial App's background js which received some info from the content script about incoming serial readings:

chrome.runtime.onMessage.addListener( 
    function(request, sender, sendResponse) {
        sendResponse("Got something!");
        console.log(request);
        var comPort = chrome.runtime.connect(extId);
        comPort.postMessage(request);

})

Then, from my understanding, I need to have the background.js listen for messages broadcasted from the Chrome serial app then forward that along to the running content script (tabs.connect) using the following code:

chrome.runtime.onConnectExternal.addListener(function(port) {
    port.onMessage.addListener(function(msg) {
        console.log(msg);

        //relay the decrement amount
        chrome.tabs.query({active:true, currentWindow:true}, function(tabs) {
            chrome.tabs.sendMessage(tabs[0].id, msg, function(response) {
                console.log("sent" + msg );
            });
        });
    });
});

And finally, setup a listener in the content script to listen for the number coming through.

chrome.runtime.onConnect.addListener(function(port) {
    port.onMessage.addListener(function(msg) {
    console.log(msg)
    // decrement the value in the ui box

    });
})

Besically. Nothing is happening. The code seems to check out but there is no communication from the serial chrome app to the extension.

Any insight would be appreciated.

EDIT: I have the serial side of things working well. The serial app's background js is chatting with the content script. Now I am just trying to pass things over to the extension which nothing seems to be coming through.

EDIT #2:
Working through it. Slowly getting there. I seem to be held up in chrome.tabs.sendMessage...
It is throwing me "cannot read property 'id' of undefined". though I swear I am writing this the right way. ***Stupid me, by defining chrome.tabs.query query info with currentWindow:true and when during debug, keeping dev tools window active, I was preventing myself from getting the actual tab information. Stupid mistake...learned that here!

Answer:1

Hi I try to receive a value from span from table like this: function getValueFromSibling(this) { var id = $(this).parent().siblings('span.childSibbling'); } Table looks like this: <tr> ...

Hi I try to receive a value from span from table like this: function getValueFromSibling(this) { var id = $(this).parent().siblings('span.childSibbling'); } Table looks like this: <tr> ...

  1. return value from init python
  2. python value from __init__
  3. value in javascript
  4. value_init
  5. value_init boost
  6. cannot return value from init
  7. g_value_init_from_instance

Is there any way to play sequence of notes in javascript piano sound. I've found a lot of libraries that can play a specific note but I assume that playing notes and making delays between would not be ...

Is there any way to play sequence of notes in javascript piano sound. I've found a lot of libraries that can play a specific note but I assume that playing notes and making delays between would not be ...

What I am trying to learn is how to spawn objects outside of the canvas from various directions...that is left, right, top, bottom. For (i = 0; i < 10; i++) { ctx.beginPath(); ctx.arc(Math....

What I am trying to learn is how to spawn objects outside of the canvas from various directions...that is left, right, top, bottom. For (i = 0; i < 10; i++) { ctx.beginPath(); ctx.arc(Math....

Can I reduce multiple variables in JavaScript? For example if I have 3 variables: var foo = 10; var boo = 15; var lol = 15; //Normal syntax: foo -=1; // -> foo will be 9 ...

Can I reduce multiple variables in JavaScript? For example if I have 3 variables: var foo = 10; var boo = 15; var lol = 15; //Normal syntax: foo -=1; // -> foo will be 9 ...

  1. reduce multiple values
  2. reduce multiple values down to a single value
  3. openmp reduction multiple variables
  4. omp reduction multiple variables