fanglingsu / vimb

Vimb - the vim like browser is a webkit based web browser that behaves like the vimperator plugin for the firefox and usage paradigms from the great editor vim. The goal of vimb is to build a completely keyboard-driven, efficient and pleasurable browsing-experience.
https://fanglingsu.github.io/vimb/
GNU General Public License v3.0
1.33k stars 99 forks source link

Inconsistent userscript behaviour #751

Closed thyssentishman closed 10 months ago

thyssentishman commented 10 months ago

Calling a function from scripts.js and evaluating javascript code directly yield different results.

Version: 3.6.0 WebKit compile: 2.40.5 WebKit run: 2.40.5 GTK compile: 3.24.38 GTK run: 3.24.38 libsoup compile: 3.4.2 libsoup run: 3.4.2 Extension dir: /usr/local/lib/vimb

Steps to reproduce

Scenario 1

Put the following in $XDG_CONFIG_HOME/vimb/config:

set scripts=true
au LoadCommitted *stackoverflow.com* eval! userscript_redirect();

Put the following in $XDG_CONFIG_HOME/vimb/scripts.js:

function userscript_redirect()
{
    window.location = 'https://duckduckgo.com';
}

Scenario 2

Put the following in $XDG_CONFIG_HOME/vimb/config:

set scripts=true
au LoadCommitted *stackoverflow.com* eval! window.location = 'https://duckduckgo.com';

Expected behaviour

When visiting a website that contains 'stackoverflow.com' in the URL, both scenarios should redirect to 'https://duckduckgo.com'.

Actual behaviour

Scenario 1: There is no redirection. Scenario 2: The page is redirected.

cdlscpmv commented 10 months ago

Try changing the autocmd event from LoadCommitted to LoadFinished (works in my case).

thyssentishman commented 10 months ago

Yes, it works for me too, but what I don't understand is why calling a function vs the command directly have different behaviors.

fanglingsu commented 10 months ago

In case of load commited the page is not loaded and therefor the js is also not injected. The redirection direct from the auto command is direct processed by vimb and webkit.

thyssentishman commented 10 months ago

I see, thanks for the explanation @fanglingsu. Closing now.