firenvim icon indicating copy to clipboard operation
firenvim copied to clipboard

Websocket error on brave (works in other browsers)

Open dileep-kishore opened this issue 3 years ago • 24 comments

  • OS Version: Manjaro Linux x86-64 (5.4.80-2-MANJARO)

  • Browser Version: Brave Browser 87.1.17.75

  • Browser Addon Version: 0.1.32

  • Neovim Plugin Version: 0.1.32

  • What I tried to do: The plugin did not work. I went through the entire Troubleshooting guide and did not get any errors in /tmp/firenvim_errors. The extension works as expected on chromium and firefox (with both default and custom settings in init.vim). I have tried turning off all the other extensions but it does not help.

  • What happened: The console reports this error -

WebSocket connection to 'ws://127.0.0.1:33109/18160844162420075250248496227241638566022564553562172694541923103911554059439334' failed: Unknown reason

Here is a complete log:

nvimui.js:4338 (2) [Array(4), {…}]
nvimui.js:4581 WebSocket connection to 'ws://127.0.0.1:35971/28604202934265641513667369465714350804237624605535763271935587662231299082685' failed: Unknown reason
neovim @ nvimui.js:sourcemap:4581
(anonymous) @ nvimui.js:sourcemap:4340

dileep-kishore avatar Dec 08 '20 23:12 dileep-kishore

This is weird, I know of several persons who managed to get Firenvim to work with Brave. Does this also happen if you use a fresh Brave profile? How did you install Brave?

glacambre avatar Dec 09 '20 04:12 glacambre

I installed brave-bin from the AUR. Here is the full version information:

Version 1.17.75 Chromium: 87.0.4280.88 (Official Build) unknown (64-bit)

I tried the extension in a new profile and this is the new error I get:

configuration.ts:79 Uncaught (in promise) Error: Error: your settings are undefined. Try reloading the page. If this error persists, try the troubleshooting guide: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md
    at getConfForUrl (configuration.ts:79)
    at getConf (configuration.ts:67)
    at content.ts:251
configuration.ts:79 Uncaught (in promise) Error: Error: your settings are undefined. Try reloading the page. If this error persists, try the troubleshooting guide: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md
    at getConfForUrl (configuration.ts:79)
    at getConf (configuration.ts:67)
    at Object.nvimify (content.ts:45)
    at forceNvimify (functions.ts:70)
    at content.ts:140
    at onMessage (browser-polyfill.js:1076)
getConfForUrl @ configuration.ts:79
getConf @ configuration.ts:67
nvimify @ content.ts:45
forceNvimify @ functions.ts:70
(anonymous) @ content.ts:140
onMessage @ browser-polyfill.js:1076

It still works on firefox and chromium.

dileep-kishore avatar Dec 09 '20 17:12 dileep-kishore

On 12/9/20 6:07 PM, Dileep Kishore wrote:

|configuration.ts:79 Uncaught (in promise) Error: Error: your settings are undefined. Try reloading the page. If this error persists, try the troubleshooting guide: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md at getConfForUrl (configuration.ts:79) at getConf (configuration.ts:67) at content.ts:251 configuration.ts:79 Uncaught (in promise) Error: Error: your settings are undefined. Try reloading the page. If this error persists, try the troubleshooting guide: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md at getConfForUrl (configuration.ts:79) at getConf (configuration.ts:67) at Object.nvimify (content.ts:45) at forceNvimify (functions.ts:70) at content.ts:140 at onMessage (browser-polyfill.js:1076) getConfForUrl @ configuration.ts:79 getConf @ configuration.ts:67 nvimify @ content.ts:45 forceNvimify @ functions.ts:70 (anonymous) @ content.ts:140 onMessage @ browser-polyfill.js:1076 |

Ah, so the problem actually is that neovim can't be started! What's the git hash of the firenvim commit currently checked out on your computer?

glacambre avatar Dec 09 '20 17:12 glacambre

I just updated and the plugin (773f50dec03e1531a58a4d041a0e2f8799ef4540) and now it does not work anywhere. I will try to go through the Troubleshooting guide again and let you know.

dileep-kishore avatar Dec 09 '20 17:12 dileep-kishore

That earlier problem was because of an updated init.vim, I am now back to experiencing the bug I reported originally (works on firefox and chromium) and not on brave. I do not have any custom firenvim config enabled.

Brave version information (installed from brave-bin AUR:

Version 1.18.70 Chromium: 87.0.4280.101 (Official Build) unknown (64-bit)

Here's the error that pops up on the console on txti.es:

nvimui.js:4338 (2) [Array(4), {…}]
nvimui.js:4581 WebSocket connection to 'ws://127.0.0.1:43287/168074330273481988215682947413511467970321057608620487688588959432893222481622' failed: Unknown reason
neovim @ VM12 nvimui.js:4581
(anonymous) @ VM12 nvimui.js:4340
FirenvimElement.ts:218 addRange(): The given range isn't in document.
(anonymous) @ FirenvimElement.ts:218
setTimeout (async)
refocus @ FirenvimElement.ts:210
detachFromPage @ FirenvimElement.ts:199
killEditor @ functions.ts:116
(anonymous) @ content.ts:150
onMessage @ browser-polyfill.js:1076
FirenvimElement.ts:218 addRange(): The given range isn't in document.
(anonymous) @ FirenvimElement.ts:218
setTimeout (async)
refocus @ FirenvimElement.ts:210
focusOriginalElement @ FirenvimElement.ts:242
_focusInput @ functions.ts:24
killEditor @ functions.ts:118
(anonymous) @ content.ts:150
onMessage @ browser-polyfill.js:1076
FirenvimElement.ts:218 addRange(): The given range isn't in document.
(anonymous) @ FirenvimElement.ts:218
setTimeout (async)
refocus @ FirenvimElement.ts:210
(anonymous) @ FirenvimElement.ts:232
setTimeout (async)
focus @ FirenvimElement.ts:231
attachToPage @ FirenvimElement.ts:157
(anonymous) @ content.ts:100
nvimify @ content.ts:90
async function (async)
nvimify @ content.ts:88

dileep-kishore avatar Dec 11 '20 17:12 dileep-kishore

Did you get a "Firenvim installed for Brave" message when you ran firenvim#install()? What does find ~ -iname "firenvim.json" print when ran in your shell?

glacambre avatar Dec 11 '20 17:12 glacambre

It installs fine for Brave, I can see the firenvim.json under ~/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts.

find ~/.config -iname "firenvim.json" prints:

find ~/.config -iname "firenvim.json"
/home/dileep/.config/chromium/NativeMessagingHosts/firenvim.json
/home/dileep/.config/google-chrome/NativeMessagingHosts/firenvim.json
/home/dileep/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts/firenvim.json

dileep-kishore avatar Dec 11 '20 17:12 dileep-kishore

This is very confusing :(

Could you insert ps -aef --forest -p $$ > /tmp/firenvim_tree in ~/.local/share/firenvim/firenvim, just before the exec line?

After doing that, try using firenvim a few times on txti.es and then please upload /tmp/firenvim_tree here (you can remove everything except the tree that contains ps -aef).

glacambre avatar Dec 11 '20 17:12 glacambre

Sure. Here it is.

 bat /tmp/firenvim_tree | grep -Ein "brave|nvim|firenvim" > /tmp/firenvim_ps

Here is the file: firenvim_ps.log

dileep-kishore avatar Dec 11 '20 17:12 dileep-kishore

I'm not seeing the ps -aef tree in your log file, did you remove it?

glacambre avatar Dec 11 '20 18:12 glacambre

I added it to ~/.local/share/firenvim/firenvim

   8   │ ps -aef --forest -p $$ > /tmp/firenvim_tree
   9   │ # exec '/usr/bin/nvim' --headless --cmd 'let g:started_by_firenvim = v:true' -c 'call firenvim#run()'
  10   │ exec '/usr/bin/nvim' --headless --cmd 'let g:started_by_firenvim = v:true' -c 'call firenvim#run()' 2>>/tmp/firenvim_errors

Then ran bat /tmp/firenvim_tree | grep -Ein "brave|nvim|firenvim" > /tmp/firenvim_ps.log on the output. Do you need the whole tree?

dileep-kishore avatar Dec 11 '20 18:12 dileep-kishore

I wanted the branch that contains the ps -aef in the hope that we would be able to learn something about the brave process that started the firenvim script (and thus ps).

I see that you've also changed the firenvim script to output errors to /tmp/firenvim_errors. Do you have anything in there?

glacambre avatar Dec 11 '20 18:12 glacambre

Ok, I couldn't find that branch. Here is the entire process tree.

firenvim_tree.log

dileep-kishore avatar Dec 11 '20 18:12 dileep-kishore

I couldn't find that branch.

That's understandable, there's lots of junk firenvim process in there :/. Does /tmp/firenvim_errors contain any information?

Could you also use the brave dev tools to inspect the headers and frames of the websocket connection? I believe the dev tools should be similar to chrome's.

glacambre avatar Dec 11 '20 18:12 glacambre

The file /tmp/firenvim_errors is empty. Looks like the WebSocket request just fails? Here are the headers:

Request URL: ws://127.0.0.1:36667/39704399542995730930256317713532052871541084053735298472541336226190112908615671

There is no response body. It just says data:undefined

dileep-kishore avatar Dec 12 '20 00:12 dileep-kishore

This is very surprising. Could you capture the traffic (basically loading txti.es + attempting to load firenvim) with wireshark/tcpdump and upload it here? Hopefully this will be the last piece of information I need to figure out what's going on.

glacambre avatar Dec 12 '20 05:12 glacambre

I finally found the problem! It looks like brave blocks this WebSocket connection as a cross-site tracker. This did not happen in earlier versions of brave. Do you have any solutions to fix this?

dileep-kishore avatar Dec 12 '20 07:12 dileep-kishore

No, I don't :/. You should probably report this issue to Brave, webextensions shouldn't be affected by the browser's tracking protections.

glacambre avatar Dec 12 '20 08:12 glacambre

I just created a post on the brave community

dileep-kishore avatar Dec 12 '20 23:12 dileep-kishore

It looks like the only option is to disable the brave adblock and use something else.

dileep-kishore avatar Dec 18 '20 16:12 dileep-kishore

Great, I guess I'll close this issue then as there's a workaround and there's nothing I can do as a webextension developper. Thanks for posting the workaround here! :)

Note that in theory there is something Brave could do to make Firenvim work with its ad blocker: firenvim only connects to localhost from an iframe whose document is located in webextension storage (that's moz-extension:// on Firefox, not sure what it is in Brave), so Brave's adblocker could check if the connection is being made from a webextension document and allow the connection if it is.

I won't be submitting this piece of information to Brave's forums because I don't want to create an account there, but feel free to do it :)

glacambre avatar Dec 18 '20 19:12 glacambre

It looks like the only option is to disable the brave adblock and use something else.

Hey man! How are you using firenvim at the moment? Do you disable the shield globally?

molleweide avatar Feb 15 '21 18:02 molleweide

I just have the trackers and ad-blocking on the shields disabled and use Ghosterly instead

dileep-kishore avatar Feb 15 '21 18:02 dileep-kishore

It seems to be working if I set the fingerprint blocking to "Standard" instead of "Strict"

McArdellje avatar May 06 '21 20:05 McArdellje