vimb icon indicating copy to clipboard operation
vimb copied to clipboard

question: when are userscripts injected?

Open herrsimon opened this issue 6 years ago • 6 comments

I stumbled upon yett and would like to use it in the userscript-file in order to block third-party javascript. For this, it is necessary that the userscript file is inserted at the top of the page before any other scripts are executed. Could you please comment a bit on how vimb injects the userscript file? Is it simply inserted at the top of the page before any scripts are executed? Thanks in advance!

herrsimon avatar Jan 05 '20 23:01 herrsimon

@herrsimon According to https://github.com/fanglingsu/vimb/blob/8ce1f06da17689f11ba0ff389b96c5b363820e23/src/setting.c#L667-L670 ist inserted at document end. There is no special reason why it is done this way, so I think you could add it at the beginning by WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START but I'm not sure if this is early enough because the documentation says that it is loaded when the document is loaded which might be a little to late.

fanglingsu avatar Jan 08 '20 22:01 fanglingsu

thanks for the information, I think it will not be too late, otherwise there is no logical reason which they make the distinction between documend start and end. I will test this in the next days. Independently of whether it is too late or not, I think it would be a good idea to change the injection time to WEBKIT_USER_SCRIPTS_INJECT_AT_DOCUMEND_START. This won't hurt anyway and injecting user scripts at the start is better in my opinion, as they should have a higher priority than site scripts.

herrsimon avatar Jan 10 '20 07:01 herrsimon

Actually, I think it would be a better idea to make the injection time configurable as a setting, for example user-scripts-inject-time=start|end or a boolean user-scripts-inject-at-start, because sometimes it is also needed to inject at the end (for example when implementing your suggestion of doing automated post requests via user script when the form data is partially provided by site scripts).

herrsimon avatar Jan 10 '20 07:01 herrsimon

@herrsimon I don't know what are the consequences of injecting the scripts at document start. But If the scripts required access to some nodes that arre written by other scripts they could also observe dom changes to determine when to run their logic. So, if it works for you to inject the scripts at start I'd do the changes here too.

fanglingsu avatar Jan 10 '20 22:01 fanglingsu

@herrsimon Did you try to inject the scripts at start? Does this affect other features of vimb?

fanglingsu avatar Feb 08 '20 20:02 fanglingsu

This issue has been automatically marked as stale because it has not had activity within the last 60 days.

stale[bot] avatar Apr 08 '20 21:04 stale[bot]