react icon indicating copy to clipboard operation
react copied to clipboard

[DevTools Bug]: Error in event handler: Error: Attempting to use a disconnected port object

Open himankpathak opened this issue 3 years ago • 36 comments

Website or app

https://codesandbox.io/s/blissful-raman-2on7k2

Repro steps

  1. Create a react app
yarn create react-app test-react
cd test-react
yarn start
  1. Create .env.development file in root.
HTTPS=true
PORT=4100
BROWSER=none
  1. Visit https://localhost:4100/ in Chrome v100.0.4896.127
  2. Open React Devtools by inspecting page, some times it shows Components tab but in large application it does not show the Components tab. If it shows the tab the error message is sent to dev tools every second.
  3. See error message in chrome://extensions/
  4. This is not reproducible in Firefox v99.0.1.

How often does this bug happen?

Every time

DevTools package (automated)

No response

DevTools version (automated)

4.24.3 (3/30/2022)

Error message (automated)

Error in event handler: Error: Attempting to use a disconnected port object

Error call stack (automated)

build/background.js:139 (lOne)

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "/build/";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 115);
/******/ })
/************************************************************************/
/******/ ({

/***/ 115:
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* global chrome */


const ports = {};
const IS_FIREFOX = navigator.userAgent.indexOf('Firefox') >= 0;
chrome.runtime.onConnect.addListener(function (port) {
  let tab = null;
  let name = null;

  if (isNumeric(port.name)) {
    tab = port.name;
    name = 'devtools';
    installContentScript(+port.name);
  } else {
    tab = port.sender.tab.id;
    name = 'content-script';
  }

  if (!ports[tab]) {
    ports[tab] = {
      devtools: null,
      'content-script': null
    };
  }

  ports[tab][name] = port;

  if (ports[tab].devtools && ports[tab]['content-script']) {
    doublePipe(ports[tab].devtools, ports[tab]['content-script']);
  }
});

function isNumeric(str) {
  return +str + '' === str;
}

function installContentScript(tabId) {
  chrome.tabs.executeScript(tabId, {
    file: '/build/contentScript.js'
  }, function () {});
}

function doublePipe(one, two) {
  one.onMessage.addListener(lOne);

  function lOne(message) {
    two.postMessage(message);
  }

  two.onMessage.addListener(lTwo);

  function lTwo(message) {
    one.postMessage(message);
  }

  function shutdown() {
    one.onMessage.removeListener(lOne);
    two.onMessage.removeListener(lTwo);
    one.disconnect();
    two.disconnect();
  }

  one.onDisconnect.addListener(shutdown);
  two.onDisconnect.addListener(shutdown);
}

function setIconAndPopup(reactBuildType, tabId) {
  chrome.browserAction.setIcon({
    tabId: tabId,
    path: {
      '16': 'icons/16-' + reactBuildType + '.png',
      '32': 'icons/32-' + reactBuildType + '.png',
      '48': 'icons/48-' + reactBuildType + '.png',
      '128': 'icons/128-' + reactBuildType + '.png'
    }
  });
  chrome.browserAction.setPopup({
    tabId: tabId,
    popup: 'popups/' + reactBuildType + '.html'
  });
}

function isRestrictedBrowserPage(url) {
  return !url || new URL(url).protocol === 'chrome:';
}

function checkAndHandleRestrictedPageIfSo(tab) {
  if (tab && isRestrictedBrowserPage(tab.url)) {
    setIconAndPopup('restricted', tab.id);
  }
} // update popup page of any existing open tabs, if they are restricted browser pages.
// we can't update for any other types (prod,dev,outdated etc)
// as the content script needs to be injected at document_start itself for those kinds of detection
// TODO: Show a different popup page(to reload current page probably) for old tabs, opened before the extension is installed


if (!IS_FIREFOX) {
  chrome.tabs.query({}, tabs => tabs.forEach(checkAndHandleRestrictedPageIfSo));
  chrome.tabs.onCreated.addListener((tabId, changeInfo, tab) => checkAndHandleRestrictedPageIfSo(tab));
} // Listen to URL changes on the active tab and update the DevTools icon.


chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  if (IS_FIREFOX) {
    // We don't properly detect protected URLs in Firefox at the moment.
    // However we can reset the DevTools icon to its loading state when the URL changes.
    // It will be updated to the correct icon by the onMessage callback below.
    if (tab.active && changeInfo.status === 'loading') {
      setIconAndPopup('disabled', tabId);
    }
  } else {
    // Don't reset the icon to the loading state for Chrome or Edge.
    // The onUpdated callback fires more frequently for these browsers,
    // often after onMessage has been called.
    checkAndHandleRestrictedPageIfSo(tab);
  }
});
chrome.runtime.onMessage.addListener((request, sender) => {
  var _request$payload, _ports$id;

  const tab = sender.tab;

  if (tab) {
    const id = tab.id; // This is sent from the hook content script.
    // It tells us a renderer has attached.

    if (request.hasDetectedReact) {
      // We use browserAction instead of pageAction because this lets us
      // display a custom default popup when React is *not* detected.
      // It is specified in the manifest.
      setIconAndPopup(request.reactBuildType, id);
    } else {
      switch ((_request$payload = request.payload) === null || _request$payload === void 0 ? void 0 : _request$payload.type) {
        case 'fetch-file-with-cache-complete':
        case 'fetch-file-with-cache-error':
          // Forward the result of fetch-in-page requests back to the extension.
          const devtools = (_ports$id = ports[id]) === null || _ports$id === void 0 ? void 0 : _ports$id.devtools;

          if (devtools) {
            devtools.postMessage(request);
          }

          break;
      }
    }
  }
});

/***/ })

/******/ });

Error component stack (automated)

No response

GitHub query string (automated)

No response

himankpathak avatar Apr 21 '22 14:04 himankpathak

Hey! Thanks for reporting. This is a known Chrome issue that is targeted to be fixed in v102. Check out #24093 for a list of potential workarounds. Closing this because it's a duplicate.

lunaruan avatar May 04 '22 18:05 lunaruan

@lunaruan The bug still exists with Chrome 115 and devTool 4.28.0. Could you provide chromium issue link about it?

woody-li avatar Aug 01 '23 09:08 woody-li

I still have the issue in Chrome Version 120.0.6099.225 (Official Build) (64-bit).

franva avatar Jan 25 '24 01:01 franva

I still have the issue in Chrome Version120.0.6099.234(正式版本) (arm64) .

michaelycy avatar Jan 25 '24 08:01 michaelycy

Still exists with Chrome 121 and devTool 5.0.0

woody-li avatar Jan 29 '24 07:01 woody-li

+1

Esty12 avatar Feb 11 '24 09:02 Esty12

I still have the issue in Chromium 122(arm64) with React Developer [email protected]

GOWxx avatar Mar 13 '24 01:03 GOWxx

I am still having the same issue, for one moment I thought something was wrong with my app. How to fix this or any update on this?

Version 123.0.6312.86 (Official Build) (64-bit) with Angular 16+

Khungersumit avatar Mar 28 '24 04:03 Khungersumit

Unfortunately, I also have this issue. Details:

Chrome: 119.0.6045.123 (Official Build) (arm64) 
React Developer Tools: 5.0.2 (3/8/2024)

puskuruk avatar Apr 08 '24 16:04 puskuruk

+1 Chrome Version 123.0.6312.87 (Official Build) (x86_64) DevTools Version: 5.0.2 img_v3_029q_5dfd989c-4863-4640-bf42-d0e7eb059e4g

muyiyr avatar Apr 10 '24 09:04 muyiyr

Still occurring:

React Developer Tools Version
5.1.0 (4/15/2024)
Chrome Version (MacBook)
Version 124.0.6367.80 (Official Build) (x86_64)

tylerjc avatar Apr 26 '24 21:04 tylerjc

I get this error message on each hot reload:

image image

browser: Arc Version 1.44.2 (50412) Chromium Engine Version 125.0.6422.112

DevTools version: 5.2.0-1717ab0171

thomastvedt avatar May 27 '24 09:05 thomastvedt

I am getting this error a lot and have yet to actually nail down what triggers it because it seems to happen so randomly. I'll occasionally leave my devtools open to go for lunch and come back to hundreds of console errors, of which 95% are this error (and the other 5% are my garbage code)

image

Stack for reference

image

Version 125.0.6422.114 (Official Build) (64-bit)

LukeParsnip avatar Jun 04 '24 13:06 LukeParsnip

any ideas for a fix/work around?

vavanv avatar Aug 01 '24 19:08 vavanv

I am facing this issue too. This especially starts arising when i open dev tools and while debugging in source tab

mohitmohlia avatar Aug 02 '24 17:08 mohitmohlia

+1

Lord-Leonard avatar Aug 06 '24 10:08 Lord-Leonard

Chrome Version 127.0.6533.89 (Official Build) (64-bit) React developer tools 5.3.1 (7/3/2024)

Uncaught Error: Attempting to use a disconnected port object at handleMessageFromPage (proxy.js:1:779)

aikrez avatar Aug 06 '24 13:08 aikrez

It appears that many developers are encountering this issue, but there hasn't been any response from the Chrome team. Are they aware of the problem? How can we bring it to their attention?

Khungersumit avatar Aug 06 '24 13:08 Khungersumit

Hey fellas, I have disabled React Developer Tools extension and so far no uncaught error during debugging. Still have Redux DevTools enabled

vavanv avatar Aug 08 '24 16:08 vavanv

it's still alive :(

sKopheK avatar Sep 16 '24 16:09 sKopheK

+1

alexdev888 avatar Sep 24 '24 10:09 alexdev888

+1

darmawan01 avatar Oct 14 '24 08:10 darmawan01

+1

fgerges avatar Oct 15 '24 16:10 fgerges

Experienced when doing hot refresh of the components. Uncaught Error: Attempting to use a disconnected port object

Uncaught Error: Attempting to use a disconnected port object at handleMessageFromPage (proxy.js:1:779)

asimsoroya avatar Oct 18 '24 00:10 asimsoroya

+1

seeketh avatar Oct 23 '24 14:10 seeketh

Still experiencing this with latest devtools

MADrickx avatar Nov 10 '24 11:11 MADrickx

still facing the issue with google chrome 129.

jiangxiaoqiang avatar Nov 17 '24 08:11 jiangxiaoqiang

It will still be called.

LTS2 avatar Nov 27 '24 07:11 LTS2

This makes debugging such a huge pain in the ass. God forbid you pause the script to debug for a minute - the whole page practically becomes unusable unless you skip all breakpoints - and adding a "Never pause here" does nothing.

This really needs to be addressed.

Nantris avatar Jan 10 '25 22:01 Nantris

@poteto @sebmarkbage I'm sorry to ping but this issue is very old, closed, and an absolute plague. Can someone please comment on the potential to truly resolve this?

Nantris avatar Jan 10 '25 22:01 Nantris