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

Error in console: Uncaught (in promise) #806

Closed
Kreash opened this issue Jun 28, 2022 · 19 comments
Closed

Error in console: Uncaught (in promise) #806

Kreash opened this issue Jun 28, 2022 · 19 comments
Labels
Bug Something isn't working Chrome For Chrome specific issues

Comments

@Kreash
Copy link

Kreash commented Jun 28, 2022

On any site, an error appears in the console:

Uncaught (in promise) {message: 'A listener indicated an asynchronous response by r…age channel closed before a response was received'} message: "A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received"

It interferes quite a lot when working in the console

Steps to Reproduce

To check, you can go to https://www.google.com/, open the console and click on an empty space.
Several errors will appear almost immediately.

Versions

  • Browser: Chrome 102.0.5005.115
@Kreash
Copy link
Author

Kreash commented Jun 28, 2022

there is also an open question on stackoverflow about this error:

https://stackoverflow.com/questions/72494154/a-listener-indicated-an-asynchronous-response-by-returning-true-but-the-messag

@philipp-classen philipp-classen self-assigned this Jun 29, 2022
@philipp-classen
Copy link
Member

I get it too with a fresh installation of Ghostery on Chromium.

A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received 

@philipp-classen philipp-classen added the Chrome For Chrome specific issues label Jun 29, 2022
@philipp-classen
Copy link
Member

Can also be reproduced on the Ghostery homepage (https://www.ghostery.com), so it is not caused by any of the scripts on the Google search page. From the Stackoverflow post, it might have started in Chrome 102 or 103.

Most likely it comes from the adblocker when it injects its code through content_script into the main page. Somewhere we are not properly handling all errors. I don't think it will affect functionality for average users, but it can be annoying for frontend developers.

Unfortunately, it is not straightforward to figure out where the error handling is missing. But error messages share that common part; at least that is a start:

   | Promise.then (async) |   |  
-- | -- | -- | --
   | (anonymous) | @ | content_script_bundle.js:1495
   | handleNewFeatures | @ | content_script_bundle.js:273
   | handleUpdatedNodes | @ | content_script_bundle.js:289
   | (anonymous) | @ | content_script_bundle.js:232

@Kreash
Copy link
Author

Kreash commented Jun 29, 2022

I first encountered this error on my ad-free project with the Ghostery extension enabled.
And at the same time, Ghostery did not block anything.
Maybe this information will help somehow

@philipp-classen
Copy link
Member

My feeling is that the code that is triggering it, is in the adblocker.

Based on the observation that handleUpdatedNodes shows up in the log, and because I don't get the error when adblocking in Ghostery is disabled.

@marcorieser
Copy link

Can confirm that the issue comes from ghostery.

@philipp-classen
Copy link
Member

Ghostery uses the webextension-polyfill library, where the issue is also discussed:
mozilla/webextension-polyfill#384

The discussion in the issues has more information, but in a nutshell, it looks like the fix from the library will be to detect Chrome's error message and treat it as a success:

mozilla/webextension-polyfill#384 (comment)

@smalluban
Copy link
Collaborator

smalluban commented Jul 26, 2022

Nevertheless, the bug is also on our site, as it should not happen, that Promise is kept in a limbo state.

philipp-classen added a commit to philipp-classen/ghostery-extension that referenced this issue Aug 11, 2022
from the webextension-polyfill (and removes the minified file). The patch
silences the following warning that started to appear in recent Chrome versions:

A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received

refs ghostery#806
@philipp-classen
Copy link
Member

From what I can tell, the functionality is not affected (e.g. the communication between the adblocker's content script and the background). Unless I'm missing something, silencing the warning (as they are discussing in the webextension-polyfill) looks like a solution.

To try it out, I created #830 which applies the open pull request.

@timint
Copy link

timint commented Aug 11, 2022

@philipp-classen That's the doctor's programming. Treat the symptoms, not the decease 😉 Do we yet not know what causes these symptoms?

@smalluban
Copy link
Collaborator

@philipp-classen As the polyfill hides the message, it does not solve the issue, and the message is there not without reason. One of the reasons is fixed here: ghostery/adblocker#2724 (and I even tried hard to make the flow the same).
@timint in short, if you create a promise by hand and return it to the event handler, but then never resolve the promise, the problematic message is shown in the console... so indeed, there are bugs in code, which produce those messages. However, Firefox just ignores that case and does not show anything. The polyfill tries to make all of the platforms work like Firefox. I am not sure if this is the best way to make a polyfill - is Firefox the only right implementation?

chrmod pushed a commit that referenced this issue Aug 12, 2022
* Apply patch mozilla/webextension-polyfill#385
from the webextension-polyfill (and removes the minified file). The patch
silences the following warning that started to appear in recent Chrome versions:

A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received

refs #806

* Added CHANGELOG
@philipp-classen
Copy link
Member

To explain the reasoning behind merging #830:

For parts like the adblocker, Ghostery needs to communicate between the background (the extension) and the content script (the website). Firefox and Chrome have similar APIs, but with a different interface - Firefox is promise-based, while Chrome uses callbacks (in Manifest V2). For that reason, we are using the webextension-polyfill library, which enables us to have a Firefox-like API on Chrome.

As part of their implementation, the polyfill library detected a specific error message from Chrome without showing a warning. In the context of Ghostery that can be seen as a implementation detail, as long as the communication between content script and background works as in Firefox. Now Chrome recently changed its code and the original error message was changed and split into two different message. That is why suppressing the warning inside the library no longer works.

The fix that is being discussed in mozilla/webextension-polyfill#384 is to update the detection code to cover the new text of the error messages. It is not merged (waiting for test coverage), but it solves the problem already in Ghostery and I could not find negative side-effects while testing it. If it gets officially merged and released, we can upgrade the library and drop the npm-patch, of course.

@philipp-classen
Copy link
Member

If there are reproducible bugs related to it, please feel free to report them. Especially, if blocking works in Firefox but breaks in Chrome.

What I'm aware of is that we currently do not reliably block YouTube ads on Chrome. We are working on a fix for that, but so far I cannot see that it is related to the warning (instead it is a race). The fix will affect the mechanism that the adblocker engine uses to inject scriptlets (replacing message passing by injecting via tabs.executeScript.

@smalluban smalluban removed their assignment Aug 16, 2022
philipp-classen added a commit to philipp-classen/common that referenced this issue Oct 7, 2022
philipp-classen added a commit to ghostery/common that referenced this issue Oct 7, 2022
@chrmod chrmod added the Bug Something isn't working label Oct 21, 2022
@sarcadass
Copy link

Hello I confirm the bug on

  • Chrome: v106.0.5249.119 (Official Build) (arm64)
  • Ghostery: v8.7.4

@chrmod
Copy link
Member

chrmod commented Oct 27, 2022

Thank you for the confirmation @sarcadass
This should be fix with the upcoming release 8.9.x - ETA one week

@philipp-classen
Copy link
Member

Also worth mentioning that on Opera and Edge, which are Chromium-based browsers, we already released the fix (part of https://github.com/ghostery/ghostery-extension/releases/tag/v8.9.1). There the error message should no longer appear. For Edge/Opera/Yandex users: If you still see it, please let us know.

For Chrome, as @chrmod said, a fix will be part of the upcoming release.

@philipp-classen
Copy link
Member

8.9.5 has been released now on all platforms.

@Kreash
Copy link
Author

Kreash commented Nov 18, 2022

It looks like after the update the error stopped repeating. Thanks

@philipp-classen
Copy link
Member

@Kreash Thanks for checking! I'll close it now, since it should work now on all Chrome-based browsers (e.g. Chrome, Edge, Opera).

For Firefox, there is a related but slightly different bug report that is still open. I'm linking it here, since the error message is similar: #707

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Chrome For Chrome specific issues
Projects
No open projects
7 participants