Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist. #67

Open
hoangvu12 opened this issue Jul 17, 2023 · 8 comments

Comments

@hoangvu12
Copy link

I'm trying to post message from web to content scripts, but for some reason it keeps showing error Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

image

Here is my content script (index.ts):

const handleDOMLoaded = async () => {
  import("./content");
};

if (document.readyState === "loading") {
  document.addEventListener("DOMContentLoaded", handleDOMLoaded);
} else {
  handleDOMLoaded();
}

content.ts:

import { allowWindowMessaging } from "webext-bridge/content-script";

allowWindowMessaging("test");

I have no idea why it causes that, it just happens whenever I call the allowWindowMessaging function.

@songpengyuan
Copy link

I also have this problem.

@zikaari
Copy link
Collaborator

zikaari commented Sep 25, 2023

Can you try not importing asynchronously? It might have something to do with that

@songpengyuan Can you also share your setup?

@hoangvu12
Copy link
Author

Can you try not importing asynchronously? It might have something to do with that

@songpengyuan Can you also share your setup?

I can't import webext-bridge without import another file asynchronously.

@ty888
Copy link

ty888 commented Aug 5, 2024

@hoangvu12 Hello, have you resolved this issue?

1 similar comment
@ty888
Copy link

ty888 commented Aug 5, 2024

@hoangvu12 Hello, have you resolved this issue?

@hoangvu12
Copy link
Author

@hoangvu12 Hello, have you resolved this issue?

I ended up writing my own messaging bridge 😔

@ty888
Copy link

ty888 commented Aug 5, 2024

image It looks like I found the reason. I need to use a message in the background script, even if it's just a dummy message.

@NickHeiner
Copy link

Hmm, I put a message in my background script as well, but it didn't solve the issue. Looks like I'm off to do #67 (comment). :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants