MCPcopy Create free account
hub / github.com/react/react / connectExtensionPort

Function connectExtensionPort

packages/react-devtools-extensions/src/main/index.js:471–498  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

469}
470
471function connectExtensionPort() {
472 if (port) {
473 throw new Error('DevTools port was already connected');
474 }
475
476 const tabId = chrome.devtools.inspectedWindow.tabId;
477 port = chrome.runtime.connect({
478 name: String(tabId),
479 });
480
481 // If DevTools port was reconnected and Bridge was already created
482 // We should subscribe bridge to this port events
483 // This could happen if service worker dies and all ports are disconnected,
484 // but later user continues the session and Chrome reconnects all ports
485 // Bridge object is still in-memory, though
486 if (lastSubscribedBridgeListener) {
487 port.onMessage.addListener(lastSubscribedBridgeListener);
488 }
489
490 // This port may be disconnected by Chrome at some point, this callback
491 // will be executed only if this port was disconnected from the other end
492 // so, when we call `port.disconnect()` from this script,
493 // this should not trigger this callback and port reconnection
494 port.onDisconnect.addListener(() => {
495 port = null;
496 connectExtensionPort();
497 });
498}
499
500function mountReactDevTools() {
501 reactPollingInstance = null;

Callers 1

index.jsFile · 0.85

Calls 1

addListenerMethod · 0.65

Tested by

no test coverage detected