Briskine / briskine

Write faster with templates and keyboard shortcuts.
https://www.briskine.com/
GNU General Public License v3.0
108 stars 23 forks source link

No quicktexts returned using chrome.runtime.onMessage/chrome.runtime.sendMessage #49

Closed xarg closed 10 years ago

xarg commented 10 years ago

Seems like sometimes the messaging protocol is not working correctly. I was able to reproduce this issue a few times, but I don't know the cause of it.

As a workaround I reload the extension (in development mode). In production, enabling and disabling doesn't fix the issue.

More investigation to be done.

Version of Chrome: 36.0.1985.125

xarg commented 10 years ago

Chrome has this way of communicating between Content Scripts (those that interact with Gmail context) and Background Scripts (those that have privileged status in the extension context). Chrome team did this in order to avoid certain security issues (like extension hijacking from random websites). It's a good thing in theory if it works - which apparently it doesn't or at least it does when it wants to.

There are 2 messaging protocols. The one we use: chrome.runtime.sendMessage() + chrome.runtime.onMessage() and the chrome.runtime.connect (which is a continuous connection ). We didn't try the last one because it seemed like an overkill. I'm gonna try rewriting this part of the communication with the connect protocol. Might be worth a try and might even improve a bit the performance when people have many quicktexts.

sprankhub commented 10 years ago

That is so awkward... Even with version 1.0.3 with the new message protocol, I have the problem that it is not working any more... It was working fine yesterday...

sprankhub commented 10 years ago

Okay I am not quite sure if that is the reason, but there was just an update for Chromium, so that I am now on Version 36.0.1985.125 Ubuntu 14.04 (283153). Now I get the following error in the console when I use the tab completion:

Discontiguous selection is not supported. content.js:13357
App.autocomplete.getCursorPosition content.js:13357
App.autocomplete.keyCompletion content.js:13091
App.autocomplete.onKey content.js:13071
App.autocomplete.onKeyDown content.js:12994
App.onKeyDown content.js:13511

Uncaught Error: Attempting to use a disconnected port object extensions::messaging:72
PortImpl.postMessage extensions::messaging:72
publicClass.(anonymous function) extensions::utils:89
App.settings.getQuicktexts content.js:12755
App.autocomplete.keyCompletion content.js:13095
App.autocomplete.onKey content.js:13071
App.autocomplete.onKeyDown content.js:12994
App.onKeyDown
xarg commented 10 years ago

At least this time there is a traceback. Thanks for the report, I'll look into it.

xarg commented 10 years ago

@sprankhub I've updated the extension once again (1.0.4). I've done some fixes and added some debug messages. So if you have an issue could you open up the console and dump the messages here?

sprankhub commented 10 years ago

I would, but 1.0.4 is not yet in the Chrome Web Store...

xarg commented 10 years ago

@sprankhub I just published it so it might take up to 1h. Sometimes it's seconds though..

sprankhub commented 10 years ago

@humanfromearth it currently works with 1.0.4 and I get the following console output if I use the tab completion:

Discontiguous selection is not supported. content.js:13365
App.autocomplete.getCursorPosition content.js:13365
App.autocomplete.keyCompletion content.js:13099
App.autocomplete.onKey content.js:13079
App.autocomplete.onKeyDown content.js:13002
App.onKeyDown content.js:13519

Discontiguous selection is not supported. content.js:13365
App.autocomplete.getCursorPosition content.js:13365
App.autocomplete.checkWord content.js:13125
(anonymous function) content.js:13069
xarg commented 10 years ago

@sprankhub yes, I have the same issue. This is related to this issue here: https://code.google.com/p/chromium/issues/detail?id=353069

It doesn't really break anything, but still annoying as it pollutes the console. I'm gonna try to find a fix for this.

xarg commented 10 years ago

@sprankhub any new issues so far with 'Tab completion'? I'm gonna start migrating all the communication to long-lived connections and wanted to know if I need to lookout for something.

sprankhub commented 10 years ago

Actually it does not work any more again :( I get the following messages multiple times when loading gmail:

Disconnected port 
Port {disconnect: function, postMessage: function, name: (...), onDisconnect: (...), onMessage: (...)} content.js:12788
Trying to reconnect content.js:12789

And when I use tab completion:

Discontiguous selection is not supported. content.js:13365
App.autocomplete.getCursorPosition content.js:13365
App.autocomplete.keyCompletion content.js:13099
App.autocomplete.onKey content.js:13079
App.autocomplete.onKeyDown content.js:13002
App.onKeyDown content.js:13519
Uncaught Error: Attempting to use a disconnected port object extensions::messaging:72
PortImpl.postMessage extensions::messaging:72
publicClass.(anonymous function) extensions::utils:89
App.settings.getQuicktexts content.js:12755
App.autocomplete.keyCompletion content.js:13103
App.autocomplete.onKey content.js:13079
App.autocomplete.onKeyDown content.js:13002
App.onKeyDown content.js:13519
xarg commented 10 years ago

I'm able to reproduce this too. I thought I fixed it :)

For some reason it disconnects after using it a few days. I'm gonna have a more detailed look later today. I'll keep you posted.

xarg commented 10 years ago

@sprankhub I released a new version of the extension: 1.0.5 - sorry about the delay...

So far so good, it seems to be working after a day. Normally previous versions broke after a while. I'm using a more sane port registration mechanism with help from https://github.com/jamesyu/gmailr

I also added a few debug messages so if yo see something 'weird' in the console please let me know. Also thanks a lot for your patience!

sprankhub commented 10 years ago

Thanks. Unfortunately, it does not work at all for me now. If I enter a short code and press TAB, the focus just jumps to the send button. No console output. Using Quicktext 1.0.5 on Chromium Version 36.0.1985.125 Ubuntu 14.04 (283153) now.

ghinda commented 10 years ago

Seems to be working for me. Both version 1.0.5 on the webstore, and the long-lived branch.

Tested on Ubuntu 14.04, chrome-unstable 39.0.2138.3 dev and chromium 36.0.1985.125 Ubuntu 14.04 (283153).

sprankhub commented 10 years ago

Just tried again with Version 36.0.1985.125 Ubuntu 14.04 (283153):

  1. Updated all extensions.
  2. Disabled all extensions except Quicktext.
  3. Reloaded gmail.
  4. Tried to use a shortcut. Same problem: Does not work at all.

When I reloaded gmail, I got the following error in the console:

Invalid gadgets.rpc token. 480640114 vs 787827748 cb=gapi.loaded_0:36
a cb=gapi.loaded_0:36
_.Mb._.sa cb=gapi.loaded_0:36
g cb=gapi.loaded_0:60
c cb=gapi.loaded_0:52

But I also get it if I disable Quicktext, so should not have something to do with the extension. But maybe that is the reason why it does not work?

xarg commented 10 years ago

@sprankhub I know this is getting old. But could you please try again. I made a bug fix (version 1.0.6), this might just fix it.

Some more details about the fix:

@ghinda The long-lived listeners where just created during 'chrome.runtime.onInstalled' event so every time a browser was restarted the connection with the long-lived connection was lost. I know.. big time fail!

sprankhub commented 10 years ago

I am on Version 37.0.2062.94 Ubuntu 14.04 (290621) (64-bit) in the meantime. Just tested with 1.0.6. Still not working at all and no error at all :/

xarg commented 10 years ago

@sprankhub do you at least get these logs:

Created shortcut port
Created search port
sprankhub commented 10 years ago

Unfortunately not. I only get the following message, but this has nothing to do with Quicktext afaik:

Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: (min-resolution: 144dpi), (-webkit-min-device-pixel-ratio: 1.5) rs=AItRSTNKX1ym07wKwLZRV5Flq3GlgYvnwg:102
Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: (min-resolution: 144dpi), (-webkit-min-device-pixel-ratio: 1.5) cb=gapi.loaded_2:324
Invalid gadgets.rpc token. 1912675216 vs 1211736253 cb=gapi.loaded_0:36a cb=gapi.loaded_0:36_.Mb._.sa cb=gapi.loaded_0:36g cb=gapi.loaded_0:60c cb=gapi.loaded_0:52
Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: (min-resolution: 144dpi), (-webkit-min-device-pixel-ratio: 1.5)
xarg commented 10 years ago

@sprankhub You're right. Those logs have nothing to do with Quicktext.

I'm guessing https://github.com/jamesyu/gmailr is not working for your because it would have dropped that line on the console.

I removed it this build bellow. Can you unarchive the zip and then in "Developer mode" in extensions try to 'Load unpacked extension...'?

Link: https://quicktext.io/static/quicktext-chrome-1.0.7.zip

sprankhub commented 10 years ago

I did. Now, when I reload Gmail, I get the logs you mentioned above. But it still does not work. If I use TAB completion, I get the following output:

Discontiguous selection is not supported. content.js:13324
    App.autocomplete.getCursorPosition content.js:13324
    App.autocomplete.keyCompletion content.js:13099
    App.autocomplete.onKey content.js:13079
    App.autocomplete.onKeyDown content.js:13002
    App.onKeyDown content.js:13478
shortcut 1 content.js:12756
shortcut 2 content.js:12761
sprankhub commented 10 years ago

Ah and I then get the following message under chrome://extensions:

Uncaught IndexSizeError: Failed to execute 'getRangeAt' on 'Selection': 0

If I click on details, it shows content.js line 13303: var range = selection.getRangeAt(0);

xarg commented 10 years ago

@sprankhub I've added an error monitoring tool to the extension. It doesn't fix anything, but I'll see the error in more detail. Can you please download the extension from the same URL:

https://quicktext.io/static/quicktext-chrome-1.0.7.zip

Cheers!

sprankhub commented 10 years ago

Oh I am sorry, I did not notice that only the standard shortcuts are available with the manually installed extension. It actually works with 1.0.7 from the post directly above this one, although I still get the error Discontiguous selection is not supported. when I use tab completion.

By the way, there is no more log output.

xarg commented 10 years ago

@sprankhub thanks. I removed a few logs so it's less verbose. Now I get the data in the trackjs directly.

Thanks a lot! I'll update the extension in the Chrome Store. I'll let you know when you can remove the one loaded from disk.

Btw, Discontiguous selection is not supported. is not actually an error. It's just a quirk in Chrome that doesn't respect the W3C standards. Nothing to worry about.

sprankhub commented 10 years ago

I just saw that the updated extension is in the Chrome Store now. Finally I can use my loved extension again - thank you very much @humanfromearth! This issue can be closed imho. Cheers!

xarg commented 10 years ago

I'm glad! Though bug to kill this was.