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.

Home Page:https://fanglingsu.github.io/vimb/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent userscript behaviour

thyssentishman opened this issue · comments

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.

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

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

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.

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