Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

port disconnect in MV3 #504

Closed
shenghuowang opened this issue Mar 5, 2021 · 5 comments
Closed

port disconnect in MV3 #504

shenghuowang opened this issue Mar 5, 2021 · 5 comments
Assignees
Labels
bug Something on the site is broken! needs more info Need more info from the reporter.

Comments

@shenghuowang
Copy link

Describe the bug
when website connect to a chrome extension(use MV3),port disconnect after several minutes

To Reproduce
Steps to reproduce the behavior:

  1. create a chrome extension use MV3, code as follow;
    chrome.runtime.onConnectExternal.addListener((port) => {

         port.onMessage.addListener((msg) => {
           // handle msg
         });
         port.onDisconnect.addListener(() => {
             //handle disconnect
         });
     });
    
  2. add extension in chrome browser

  3. in my website, connet to this extension, code as follow:
    let port = chrome.runtime.connect(extensionId, { name: id });
    this.port.onMessage.addListener((msg) => {
    // handle msg
    });
    port.onDisconnect.addListener(() => {
    // handle disconnect
    });

  4. See error
    after several minutes(about 5-6 minutes),my website receive port disconnect

Expected behavior
port not disconnect, keep live connection

Additional context
when extension change to MV2, this bug not happen, it seems to be a bug in MV3

@shenghuowang shenghuowang added the bug Something on the site is broken! label Mar 5, 2021
@robdodson
Copy link
Contributor

@shenghuowang is this related to a specific doc on developer.chrome.com? If not, it might be better to ask this on https://stackoverflow.com/

@robdodson robdodson added the needs more info Need more info from the reporter. label Mar 8, 2021
@tophf
Copy link

tophf commented Mar 9, 2021

Service workers in Chrome auto-disconnect any external connections such as extension ports after five minutes forcibly. This is a breaking change for thousands of extensions so it must be mentioned in the documentation. Ideally, though, this timer should not apply to extensions at all.

Edit: this is mentioned in https://bugs.chromium.org/p/chromium/issues/detail?id=1146434

@dotproto
Copy link
Contributor

dotproto commented Mar 25, 2021

Closing as this is a Chromium issue (1146434), not a documentation bug.

@ShaoboLiu
Copy link

The same issue happened in my project of MV3.

runtime.connect successfully, and postMessage a few times successfully. However, after 5 minutes, onDisconnect event triggered. Looks like automatically lost connection. I don't know what is the reason.

@qhkm
Copy link

qhkm commented Feb 5, 2023

I'm having this issue right now with my chrome extension. Would appreciate an update on the issue I am experiencing. Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something on the site is broken! needs more info Need more info from the reporter.
Projects
None yet
Development

No branches or pull requests

6 participants