akhodakivskiy / VimFx

Vim keyboard shortcuts for Firefox
https://addons.mozilla.org/firefox/addon/vimfx
Other
1.42k stars 174 forks source link

VimFx 0.26.0 doesn't work when extensions.VimFx.config_file_directory is set to "~/vimfx" #994

Closed Ace-Who closed 1 year ago

Ace-Who commented 1 year ago

When extensions.VimFx.config_file_directory is set to "~/vimfx", VimFx 0.26.0 doesn't work and the Browser Console outputs:

1685894585359 addons.xpi WARN Exception running bootstrap method startup on VimFx-unlisted@akhodakivskiy.github.com: ReferenceError: PathUtils is not defined(chrome://vimfx/content/lib/config.js:57:3) JS Stack trace: loadFile@config.js:57:3

girst commented 1 year ago

Sorry, I really dropped the ball with testing of the last release. v0.26.1 out now!

Ace-Who commented 1 year ago

Still not working:

1686032659989 addons.xpi WARN Exception running bootstrap method startup on VimFx-unlisted@akhodakivskiy.github.com: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://vimfx/content/lib/config.js :: loadFile :: line 60" data: no] Stack trace: loadFile()@config.js:60

girst commented 1 year ago

On Mon, Jun 05, 2023 at 11:50:38PM -0700, Ace-Who wrote:

Still not working:

1686032659989 addons.xpi WARN Exception running bootstrap method startup on @.: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://vimfx/content/lib/config.js :: loadFile :: line 60" data: no] Stack trace: @.:60

please share your about:config values for

also, firefox version and operating system please

Ace-Who commented 1 year ago

The info above is true on both versions of Firefox following:

Ace-Who commented 1 year ago

I don't know why security.sandbox.content.read_path_whitelist is not present now, but I created it again and set it to C:\Users\***\vimfx then restarted Firefox and got the same warning.

图片

1686103598415 addons.xpi WARN Exception running bootstrap method startup on VimFx-unlisted@akhodakivskiy.github.com: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://vimfx/content/lib/config.js :: loadFile :: line 60" data: no] Stack trace: loadFile()@config.js:60

girst commented 1 year ago

On Tue, Jun 06, 2023 at 07:19:17PM -0700, Ace-Who wrote:

I don't know why security.sandbox.content.read_path_whitelist is not present now, but I created it again and set it to C:\Users\***\vimfx then restarted Firefox and got the same warning.

read_path_whitelist must end in a slash, so it should be C:\Users\***\vimfx\

girst commented 1 year ago

ok, this is an issue with windows. previously, vimfx 0.25.0 used this code:

const {OS} = ChromeUtils.import('resource://gre/modules/osfile.jsm'); let path = OS.Path.toFileURI("C:/");

this returned "file://C:", as expected.

both replacements, PathUtils.toFileURI("C:/") and new FileUtils.File("C:/"), cannot handle windows drive letters, possibly also with backslashes.

i don't have a windows computer to test, but please try the following:

  1. open a browser console a. press f12, then f1 to open devtools settings b. check "enable browser chrome and add-on debugging" c. check "enable remote debugging" d. press ctrl+shift+j to open a browser console
  2. type (new FileUtils.File("/Users/***/vimfx")).exists()

does this also raise an error? if not, does it return true or false? try using this for the path in extensions.VimFx.config_file_directory

Ace-Who commented 1 year ago

Now I set security.sandbox.content.read_path_whitelist to C:\Users\***\vimfx\.

(new FileUtils.File("/Users/***/vimfx")).exists() raises an error:

Uncaught NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]
    <anonymous> debugger eval code:1
    getEvalResult resource://devtools/server/actors/webconsole/eval-with-debugger.js:251
    evalWithDebugger resource://devtools/server/actors/webconsole/eval-with-debugger.js:172
    evaluateJS resource://devtools/server/actors/webconsole.js:960
    evaluateJSAsync resource://devtools/server/actors/webconsole.js:851
    makeInfallible resource://devtools/shared/ThreadSafeDevToolsUtils.js:103
debugger eval code:1:2

I did replace *** with actual user name.

try using this for the path in extensions.VimFx.config_file_directory

Sorry I don't get what does "this" mean.

hayatogh commented 1 year ago

For anyone experiencing this issue, just emptying extensions.VimFx.config_file_directory let us use VimFx with previously loaded configs 😄 👍 , if you have a simple config.js which only set some keys and an empty frame.js like me, because all key settings are stored in about:config values.

So, I would also suggest that we surround file loading part of code with try-catch for future breakage of them again. It's such a pain VimFx is not loaded and not usable at all...


First, thank you for supporting this great extension @girst ! I'm experiencing the same issue on Windows and I did some tests. I hope this helps.

security.sandbox.content.read_path_whitelist was empty and I also created as C:\Users\username\.vimfx\ I tried following values as extensions.VimFx.config_file_directory and the FileUtils.File() argument.

--- when set extensions.VimFx.config_file_directory FileUtils.File("%s").exists()
~/.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_FILE_UNRECOGNIZED_PATH
~\.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_FILE_UNRECOGNIZED_PATH
~\\.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_FILE_UNRECOGNIZED_PATH
C:\Users\username\.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH false
C:/Users/username/.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_FILE_UNRECOGNIZED_PATH
file:///C:/Users/username/.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_FILE_UNRECOGNIZED_PATH
C:\\Users\\username\\.vimfx NS_ERROR_FILE_UNRECOGNIZED_PATH true
girst commented 1 year ago

On Fri, Jun 09, 2023 at 04:54:51AM -0700, matsuhav wrote:

--- | when set extensions.VimFx.config_file_directory | FileUtils.File("%s").exists() C:\\Users\\username\\.vimfx | NS_ERROR_FILE_UNRECOGNIZED_PATH | true

i see why this fails in config_file_directory: in config.coffee line 49, I concat the paths with '/', regardless of operating system. note that the double backslashes for the FileUtils.File check are a red herring: they only need to be doubled up for the browser console.

can you please run another experiment for me, @matsuhav? what's the output of the following two expressions when executed in the browser console:

Services.dirsvc.get('Home', Ci.nsIFile).path

Services.io.newFileURI(new FileUtils.File("C:\foo\bar")).spec

hayatogh commented 1 year ago

Of course! The output is below. The first one showed double backslashes and I pasted here as is. Double backslashes thing is so tricky..

Services.dirsvc.get('Home', Ci.nsIFile).path
"C:\\Users\\username"
Services.io.newFileURI(new FileUtils.File("C:\\foo\\bar")).spec
"file:///C:/foo/bar"
girst commented 1 year ago

vimfx-testbuild.zip

thanks, i think i got it now. instead of a premature release, i do what i should have done from the beginning and attach a test build. can both of you please try the attached xpi? here's the diff in case you're curious.

i'll have to do the try-catch logic you suggested.

hayatogh commented 1 year ago

Thank you very much! Now ~\.vimfx and C:\Users\username\.vimfx works without errors as extensions.VimFx.config_file_directory values! 👍

~/.vimfx still shows the same error but I think it's OK. Though I think it was working in 0.25.0, it's so trivial for Windows users to use back slashes when they set extensions.VimFx.config_file_directory but on the other hand, it can be complicated and error prone for VimFx to translate forward slashes to back slashes. VimFx is in maintenance mode, so the try-catch is also optional thing of course.

girst commented 1 year ago

On Fri, Jun 09, 2023 at 07:23:28AM -0700, matsuhav wrote:

Thank you very much! Now ~\.vimfx and C:\Users\username\.vimfx works without errors as extensions.VimFx.config_file_directory values! 👍

once again, i have to apologize for just how much i bungled the fix for this in the last releases. i intend to do better, for my own pride.

~/.vimfx still shows the same error but I think it's OK. Though I think it was working in 0.25.0, it's so trivial for Windows users to use back slashes when they set

yes, i belive this used to work. sadly, the firefox code that handled that (osfile.jsm) was removed. and ...

extensions.VimFx.config_file_directory but on the other hand, it can be complicated and error prone for VimFx to translate forward slashes to back slashes.

.. that's right. this is why we let the built-in code handle it. i won't be accepting patches to work around this. sorry windows users :|

VimFx is in maintenance mode, so the try-catch is also optional thing of course.

i feel like this might not be necessary any more. i had a quick look and most of the relevant code is already in a try-catch block. only building a file:// uri from config_file_directory isn't. and now that this is properly implemented, using modern mozilla code, i don't think it will break again any time soon (famous last words, i know).

hayatogh commented 1 year ago

Rejecting forward slashes as Windows' path separator is Firefox's decision, so VimFx follows it and I have no objection. And I agree that we don't need the try-catch block because you cleanly implemented code with Firefox built-ins. Thank you again.

girst commented 1 year ago

https://github.com/akhodakivskiy/VimFx/releases/tag/v0.26.2

Ace-Who commented 1 year ago

I don't know the details about code, but doesn't Windows accept both slashes and backslashes as path separators?

vimfx-testbuild.zip

I tested this on Firefox Nightly 116.0a1 in my daily used profile. For config_file_directory, neither ~/vimfx nor ~\vimfx works and both raise an error:

1686324861418   addons.xpi  WARN    Exception running bootstrap method startup on VimFx@akhodakivskiy.github.com: TypeError: can't access property "startsWith", aId is undefined(resource:///modules/CustomizableUI.sys.mjs:1713:1) JS Stack trace: isSpecialWidget@CustomizableUI.sys.mjs:1713:1

But in a test profile ~\vimfx works. Then I installed VimFx v0.25.0 to try my luck, and it works. Then I intalled the test build again, and it works too. However seems they both raise an error like this:

1686329512705   addons.xpi  WARN    Exception running bootstrap method startup on VimFx-unlisted@akhodakivskiy.github.com: [Exception... "File error: Not found"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: chrome://vimfx/content/lib/utils.js :: <TOP_LEVEL> :: line 6"  data: no] Stack trace: utils.js:6

After I noticed the VimFx version was still shown as 0.25.0, I thought was I expected to always do a clean install? Then I clean install v0.25.0 again and It doesn't work as expected. Then a clean installed test build works again, and no error.

Ace-Who commented 1 year ago

For prudential reasons, is it right that when referring to errors I ignore this common one?

VimFx: Fission is enabled in your browser. VimFx will not be able to interact with third party iframes. main.js:127
girst commented 1 year ago

On Fri, Jun 09, 2023 at 10:13:00AM -0700, Ace-Who wrote:

I don't know the details about code, but doesn't Windows accept both slashes and backslashes as path separators?

we use a piece of firefox code to handle paths. that firefox code stopped accepting / on windows (it seems).

I tested this on Firefox Nightly 116.0a1 in my daily used profile. For config_file_directory, neither ~/vimfx nor ~\vimfx works and both raise an error:

1686324861418 addons.xpi WARN Exception running bootstrap method startup on @.: TypeError: can't access property "startsWith", aId is undefined(resource:///modules/CustomizableUI.sys.mjs:1713:1) JS Stack trace: @.:1713:1

this has nothing to do with this bug; i don't know what is broken here without backtraces. uninstall vimfx completely and reinstall it.

But in a test profile ~\vimfx works. Then I installed VimFx v0.25.0 to try my luck, and it works. Then I intalled the test build again, and it works too. However seems they both raise an error like this:

1686329512705 addons.xpi WARN Exception running bootstrap method startup on @.***: [Exception... "File error: Not found" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: chrome://vimfx/content/lib/utils.js :: :: line 6" data: no] Stack trace: utils.js:6

have you set security.sandbox.content.read_path_whitelist?

When I noticed the VimFx version was still shown as 0.25.0, I thought was I expected to always do a clean install? Then I clean install v0.25.0 again and It doesn't work as expected. Then a cleaned installed test build works again, and no error.

then you have installed something else. remove vimfx completely and install it fresh (your config is stored in about:config, so you won't lose anything)

On Fri, Jun 09, 2023 at 10:25:58AM -0700, Ace-Who wrote:

For prudential reason, is it right that when referring to errors I ignore this common one:

VimFx: Fission is enabled in your browser. VimFx will not be able to interact with third party iframes. main.js:127

yes, you can ignore that. or fix it ;) => https://github.com/akhodakivskiy/VimFx/blob/master/documentation/known-bugs.md#fission

Ace-Who commented 1 year ago

Thank you.

have you set security.sandbox.content.read_path_whitelist?

Yes. Anyway everything is OK now, provided extensions.VimFx.config_file_directory is set to ~\vimfx.

yes, you can ignore that. or fix it ;) => https://github.com/akhodakivskiy/VimFx/blob/master/documentation/known-bugs.md#fission

Oh, I must have read this and forgot it.

girst commented 1 year ago

On Mon, Jun 12, 2023 at 03:10:34AM -0700, Ace-Who wrote:

Thank you.

have you set security.sandbox.content.read_path_whitelist?

Yes. Anyway everything is OK now, provided extensions.VimFx.config_file_directory is set to ~\vimfx.

good to hear! reach out again if anything breaks again :)

yes, you can ignore that. or fix it ;) => https://github.com/akhodakivskiy/VimFx/blob/master/documentation/known-bugs.md#fission

Oh, I must have read this and forgot it.

-- Reply to this email directly or view it on GitHub: https://github.com/akhodakivskiy/VimFx/issues/994#issuecomment-1587020527 You are receiving this because you modified the open/close state.

Message ID: @.***>