quoid / userscripts

An open-source userscript manager for Safari
https://quoid.github.io/userscripts/
GNU General Public License v3.0
3.31k stars 188 forks source link

No injection with Javascripts from OpenUserJS #45

Closed entisocial closed 4 years ago

entisocial commented 4 years ago

Hello, first congrats on the update, the intention behind it is good and will make it more powerful than the previous one. However for now, it isn't working for me as it doesn't inject anything. I've tried with several scripts and none work (while they work without issues on other browsers and extensions including the old version of yours). I added the scripts by using the toolbar button, then +, then pasted my script, then saved > nothing. I disabled and enabled > nothing. I closed Safari and reopened it > nothing. I tried to change the metadata > nothing. I tried to open the app outside of Safari (it was no use) I'm using Safari version 13.1.1 (15609.2.9.1.2) on 10.15.5 if that helps.

quoid commented 4 years ago

@entisocial

I'd like to confirm whether this is an issue with the extension or the userscript(s) you are attempting to use.

Can you please try the following:

1 - create a new javascript userscript 2 - paste the below code into the editor:

// ==UserScript==
// @name        Injecion Test
// @description Testing the extension
// @match       *://*.*
// ==/UserScript==

alert("test");

3 - save 4 - visit any website

After saving that userscript, when you visit websites you should see an alert that says "test". Note, you can disable the script by either deleting it or clicking on the toggle button once you confirm functionality is working or not.

Please let me know if that works or not. If it does work, please provide me with an example userscript that was not previously working (preferably a simple one).


Here are some extra notes:

entisocial commented 4 years ago

Ok, the test does work properly. For instance this script https://openuserjs.org/scripts/tumpio/Endless_Google/source works with InjectJS, but doesn't with Userscripts. Also, as I said I edited my metadata to try to make them compliant, but it didn't change anything.

quoid commented 4 years ago

OK, then this is technically a userscript (source file) issue, not an extension functionality bug.

Taking a look at the script you've linked, it does not have the required metadata fields in order to run - see docs

@match (optional) - Domain match patterns; you can use several instances of this metafield if you'd like multiple domain matches. If you omit this metafield, the userscript will never run. View this article for more information on constructing patterns

I can see that the script you linked uses the old way of matching domains, with // @include. Userscript Safari does not support that metadata field. Theoretically if the // @include value is a string or conforms to a match pattern, you could change @include to @match and it could/should work.

I tried that with the script you linked and injection did happen when switching from @include to @match, however it looks like the script is severely outdated and did not function.

Some userscripts will contain metadata fields that are not supported by this extension. There are plans to implement support for more fields, specifically focusing on fields that augment functionality (such as @run-at, @downloadURL, etc...). I am unsure if @inject will be priority, but I think making it an alias for @match could be a good idea.

entisocial commented 4 years ago

Oh nice, indeed replacing @include by @match fixes my unworking scripts, thanks for the tip! I did read the doc about @match but I got confused with it being "optional" and at the same time mandatory for the script to run plus I overlooked the fact that my scripts were using @include instead. But it's all working now thanks again for your good work 👍🏻

quoid commented 4 years ago

Now that you point that out, the wording is awkward. The field is bot needed to save but required to run the script.

I'll try to make that more clear.