ghostery-extension
ghostery-extension copied to clipboard
Error in console: Uncaught (in promise)
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
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
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
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
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
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.
Can confirm that the issue comes from ghostery.
Ghostery uses the webextension-polyfill library, where the issue is also discussed: https://github.com/mozilla/webextension-polyfill/issues/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:
https://github.com/mozilla/webextension-polyfill/issues/384#issuecomment-1151139451
Nevertheless, the bug is also on our site, as it should not happen, that Promise is kept in a limbo state.
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 https://github.com/ghostery/ghostery-extension/pull/830 which applies the open pull request.
@philipp-classen That's the doctor's programming. Treat the symptoms, not the decease 😉 Do we yet not know what causes these symptoms?
@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: https://github.com/ghostery/adblocker/pull/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?
To explain the reasoning behind merging https://github.com/ghostery/ghostery-extension/pull/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 https://github.com/mozilla/webextension-polyfill/issues/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.
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.
Hello I confirm the bug on
- Chrome:
v106.0.5249.119 (Official Build) (arm64)
- Ghostery:
v8.7.4
Thank you for the confirmation @sarcadass This should be fix with the upcoming release 8.9.x - ETA one week
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.
8.9.5 has been released now on all platforms.
It looks like after the update the error stopped repeating. Thanks
@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: https://github.com/ghostery/ghostery-extension/issues/707