dhowe / ChinaEye

Experience the web as if you were living in China...
Artistic License 2.0
9 stars 3 forks source link

Use "Long-lived connections" for messaging #25

Closed dhowe closed 6 years ago

dhowe commented 7 years ago

Not sure if an actual problem:

Uncaught Error: Attempting to use a disconnected port object
    at PortImpl.postMessage (extensions::messaging:60:13)
    at Port.publicClassPrototype.(anonymous function) [as postMessage] (extensions::utils:149:26)
    at responseCallback (extensions::messaging:166:16)
    at Object.success (chrome-extension://bmlfgnkacjnbhefiokiheiohpeiomidk/js/background.js:129:7)
    at i (chrome-extension://bmlfgnkacjnbhefiokiheiohpeiomidk/js/jquery-2.2.3.js:2:27151)
    at Object.fireWith [as resolveWith] (chrome-extension://bmlfgnkacjnbhefiokiheiohpeiomidk/js/jquery-2.2.3.js:2:27914)
    at z (chrome-extension://bmlfgnkacjnbhefiokiheiohpeiomidk/js/jquery-2.2.3.js:4:12120)
    at XMLHttpRequest.<anonymous> (chrome-extension://bmlfgnkacjnbhefiokiheiohpeiomidk/js/jquery-2.2.3.js:4:15680)
cqx931 commented 7 years ago

Need to use "Long-lived connections" instead of one-time connection to avoid this error. vAPI.messaging in uBlock uses "Long-lived connections".

Reference: http://stackoverflow.com/questions/5337672/reason-for-uncaught-error-attempting-to-use-a-disconnected-port-object

dhowe commented 7 years ago

post-initial release

cqx931 commented 7 years ago

The limitation about one-time messaging is that it has to be popup/content page that initialize the messaging and then the background page answers.

This could be problematic if the popup is asking for blockingStatus to the background when the background is still checking the server. Currently the popup won't get refreshed when the message is ready. To do so, what I can think about are two methods:

  1. One-time messaging
    Ask for getBlockingStatus again with setInterval. But this could possibly lead to extra requests to greatfirewallofchina if the internet is slow...(if Blocking Status is not available, it checks the page) But maybe it can be solved by this https://github.com/dhowe/ChinaEye/issues/44?

  2. Long-lived messaging
    Update the popup when the check is done. (This seems to be the best practice for me)

dhowe commented 6 years ago

Good -- How much time do you estimate to switch to long-lived messaging?

cqx931 commented 6 years ago

Please check: https://github.com/dhowe/ChinaEye/pull/75

dhowe commented 6 years ago

Good -- shall we publish an update?

cqx931 commented 6 years ago

Yes, I'm going to close this and go through the release testing in a new ticket