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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:41:27+00:00 2026-06-13T10:41:27+00:00

Trying to communicate between my background.js and contentscript.js manifest.json { name: xxx, version: 0.1,

  • 0

Trying to communicate between my background.js and contentscript.js

manifest.json

{
    "name": "xxx",
    "version": "0.1",
    "manifest_version": 2,

    "permissions": [
        "tabs"
    ],

    "description": "xxx",
    "icons": { "16": "icon16.png",
               "48": "icon48.png",
               "128": "icon128.png" },

    "browser_action": {
        "default_title" : "xxx",
        "default_icon": "icon16.png",
        "default_popup": "popup.html"
    },

    "background": {
        "scripts": ["background.js"]
    },

    "content_scripts" : [
    {
        "matches" : [ "http://*/*" ],
        "js" : [ "contentscript.js", "jquery.js" ]
    }
  ]
}

background.js

var listePdt = {};
var selectedPdt = null;
var selectedId = null;

function updatePdt(tabId)
{
    chrome.tabs.sendMessage(tabId, {}, function(pdt) {
            chrome.pageAction.show(tabId);
    });
}

chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
    if(change.status == "complete")
    updatePdt(tabId);
});

chrome.tabs.onSelectionChanged.addListener(function(tabId, info) {
    selectedId = tabId;
    // and other things
});

chrome.tabs.getSelected(null, function(tab) {
    updatePdt(tab.id);
});

contentscript.js

if(window == top)
{
    chrome.extension.onMessage.addListener(
        function(req, sender, sendResponse) {
            sendResponse(findPdt());
        }
    );
}

var findPdt = function() {

    // operations on a string

    return "string";
}

But I get the following error “Port error: Could not establish connection. Receiving end does not exist” in console for generated background page … dont understand why .

Any help plz ?

  • 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-13T10:41:29+00:00Added an answer on June 13, 2026 at 10:41 am

    One thing that stands out is:

    chrome.tabs.getSelected(null, function(tab) {
        updatePdt(tab.id);
    });
    

    It is currently deprecated (see here and here), and the new way looks like this (note that windowId: chrome.windows.WINDOW_ID_CURRENT is included as well to account for cases where you have multiple Chrome instances open (I had a number of them, apparently 🙂 ).

    chrome.tabs.query(
      {windowId: chrome.windows.WINDOW_ID_CURRENT, active: true}, function(tab) {
      updatePdt(tab.id);
      } );
    

    However as to your main problem, this (and getSelected) will both throw the Port error you are seeing when you load the extension from chrome://extensions, the New tab screen, or any other ‘non-standard’ page (Bookmarks, View Source, Inspect Element itself, etc.), so I would just disregard them. With your code, reload the extension, open your Inspect Element window, then go to another tab in your browser and reload the page – you should see the desired action complete (I added a console.log(pdt); call as part of the sendMessage call, and the requested value was returned. In other words, everything seemed to work fine 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to communicate between my Content- and Background Script I get the following
I have been trying to communicate between two CodeIgniter projects. I have 2 projects,
I am trying to communicate between an applet and a servlet. I first tried
I am trying to communicate between two Windows applications in Delphi. Sender sends commands
I am trying to communicate between two android emulators for communication , thus I
I'm trying to communicate between a flex 4.1 application to a flash action script
I am trying to communicate between two processes. From MSDN Documentation, I came across
I'm trying to communicate between my PC (Windows 7 using Netbeans and RXTX) with
I'm trying to communicate between two computers through the TCP/IP protocol on C++. I'm
I am trying to communicate between 2 applications. 1 matlab application 1 C# written

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.