quoid / userscripts

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

iOS + iPadOS Support #135

Closed Kartik-715 closed 2 years ago

Kartik-715 commented 3 years ago

With the release of iPadOS and iOS 15, do you have plans to migrate this extension to a safari web extension? Could be pretty useful!

v7rzlhb3xg commented 2 years ago

Yes, the same error persists even after refreshing, changing the folder, restarting safari.

quoid commented 2 years ago

Yes, the same error persists even after refreshing, changing the folder, restarting safari.

:(

Ok, I am going to try some more things. Possibly a new build today. There's something that's screwing up the native messaging. I also noticed a random Couldn't Communicate with a helper application error when testing, which I think is related to the Files.app.

bradenglund commented 2 years ago

Yes, the same error persists even after refreshing, changing the folder, restarting safari.

Same true for me.

EthanG45 commented 2 years ago

@Kartik-715 @willl @madman404 @Reinachan @julianpomper @EthanG45 @RedGuy12 @a9eelsh and anyone else viewing this thread. Version 0.1.0 beta for iOS got approved for testflight.

If you want to test, please sign up here: https://forms.gle/QB46uYQHVyCxULue9 - don't forget to use the email associated with your Testflight account. Even if you signed up in the past to beta test, you need to re-sign up because I just purged the old tester pool, to prevent sending unwanted Testflight invites.

I reckon this first version will be rough, so please adjust expectations. At the current time I am mainly looking for iPhone testers running iOS 15+. The iPad version doesn't really work at the moment (visual bugs with the popover).

Already filled all slots?

a9eelsh commented 2 years ago

Can I try the app?

quoid commented 2 years ago

@EthanG45

There's a major issue that is preventing, I assume, all users from being able to interact with the popup. Because of this I've closed sign ups until it becomes stable.

I've been digging into this all morning trying numerous work arounds and nothing seems to be working. I am guessing here, but I think the issue could be:

quoid commented 2 years ago

I just pushed build 4, in a possibly futile attempt to pin down this issue. I disabled remote fetching as I think I was noticing a pattern with those functions and the issue ¯_(ツ)_/¯

@EthanG45 shoot me an email if you want to give it a shot (its in my profile)

a9eelsh commented 2 years ago

I just pushed build 4, in a possibly futile attempt to pin down this issue. I disabled remote fetching as I think I was noticing a pattern with those functions and the issue ¯(ツ)

@EthanG45 shoot me an email if you want to give it a shot (its in my profile)

Can I send an email to try?

v7rzlhb3xg commented 2 years ago

Still getting “Something went wrong” when pointing to a directory with .js files but no number this time. Setting it to any other directory lets me get farther into the update UI than I was able to before though! 977662C3-2E12-439B-A5A3-3B9BFF120C9B

quoid commented 2 years ago

@a9eelsh if you want, but I am not sure it will work ^^

@v7rzlhb3xg Damn. I installed it through Testflight on a friends iPad 6th gen that has no association with my dev account and was having the same issues as everyone else. Once I disabled remote fetching, I didn't experience the issue any longer. I did however plug the ipad into a macbook (again no association with my dev account) and inspected the popup through Safari "develop" menu to check the console.

Do you have any "undownloaded" files in your Files.app icloud folder?

IMG_510D041BEA80-1

a9eelsh commented 2 years ago

@a9eelsh if you want, but I am not sure it will work ^^

@v7rzlhb3xg Damn. I installed it through Testflight on a friends iPad 6th gen that has no association with my dev account and was having the same issues as everyone else. Once I disabled remote fetching, I didn't experience the issue any longer. I did however plug the ipad into a macbook (again no association with my dev account) and inspected the popup through Safari "develop" menu to check the console.

Do you have any "undownloaded" files in your Files.app folder?

yse i need try this

quoid commented 2 years ago

@a9eelsh email me if you want to try

a9eelsh commented 2 years ago

@a9eelsh email me if you want to try

done

v7rzlhb3xg commented 2 years ago

@quoid Great news! No more error! I believe you were right the first time -- it's most likely a memory issue. There was a rather large userscript (1.1MB) in the original folder I've been trying to use. After trying with a new folder and a smaller test user script (9KB) the error is gone. I don't believe whether I had undownloaded files in my iCloud downloads folder seemed to make a difference, but I emptied it just in case.

quoid commented 2 years ago

@v7rzlhb3xg

Interesting! We are making progress!

I am still unsure if it is a memory issue or something to do with remotely fetching code/data, or perhaps both are related.

As mentioned in previous comments, I almost completely stopped experiencing the issue on my personal iPhone. I thought that perhaps because that was associated and used with my developer account something made it less prone to the issue. However, this afternoon I was able to reproduce the issue again on my phone.

I noticed that during the popup init phase, when I was checking for required resources (@require key in userscripts), the error would appear. It seemed related to the remote data fetching I was doing. This most recent update disabled all of that, which is not optimal for version 1 of the iOS app, but gives me some insight into what might be causing the issue.

I am curious if the userscript you removed relied on the @require key or @updateURL key.

Version 3 is still available, so if you want to try re-installing that version and seeing if the error reappears, even though you removed that file, that would be super helpful 😄

a9eelsh commented 2 years ago

I am curious if the userscript you removed relied on the @require key or @updateURL key.

not show extension in setting

i'm use ipad, but iphone show no problem

v7rzlhb3xg commented 2 years ago

@quoid I can't seem to find Version 3 under previous builds in TestFlight, only the latest Version 4 is showing up for me.

In the meantime, I did some more testing. The large script that was causing problems did in fact have @updateURL but still throws the error even with that removed. Deleting that script from my userscript folder resolves the issue again. Maybe there's something else in there that's problematic?

EthanG45 commented 2 years ago

@quoid I just installed the beta on my iPhone 13 Pro Max and iPad Pro 2018 12.9" both running iOS/iPadOS 15.0.2. There were some UI bugs, but it loaded up my scripts folder from my macOS version of user scripts and correctly loaded in my FrankerFaceZ script for Twitch. Will continue testing but this seems to be working so far!

bradenglund commented 2 years ago

@quoid Great news! No more error! I believe you were right the first time -- it's most likely a memory issue. There was a rather large userscript (1.1MB) in the original folder I've been trying to use. After trying with a new folder and a smaller test user script (9KB) the error is gone. I don't believe whether I had undownloaded files in my iCloud downloads folder seemed to make a difference, but I emptied it just in case.

I also was able to get it to load by using a very small single file in a directory by itself. https://openuserjs.org/scripts/mscarchilli/Amazon_Smile_Redirect E42EA60D-0A3A-4E54-B95E-4E36133C2215

It is not actually executing the script as I am still on www.amazon.com, but it's a start.

Unfortunately, if I switch directories back to the one with several scripts, "Something went wrong" with no numerical code. I also tried another single js file, it fails for that too. For reference, this is another I am testing with. https://github.com/SteppoFF/ita-matrix-powertools/

bradenglund commented 2 years ago

I was also able to reproduce the results of the amazon smile script with this script. https://github.com/hjk789/NXEnhanced/tree/master/Userscript

quoid commented 2 years ago

@v7rzlhb3xg

Deleting that script from my userscript folder resolves the issue again. Maybe there's something else in there that's problematic?

I'm still unsure what the actual cause is. I was thinking that maybe it was remote file content fetching, but maybe that isn't the actual cause. Maybe you (and me) were getting that issue because when requesting remote file contents, the pay load made the extension exceed the memory limit (this is just a guess).

For my userscripts, I have 2 in particular that request large-ish libraries (~100kb), so I am wondering if that could be it.

Either way, it's clear more testing is needed all around.

quoid commented 2 years ago

@bradenglund

It is not actually executing the script as I am still on www.amazon.com, but it's a start.

I downloaded the first Amazon Smile script and it was executing, but the code was made for the desktop site. This element: document.getElementById('nav-tools'); is required for the script to redirect and it doesn't exist on the mobile site.

with no numerical code

I removed the numerical code in the latest build as it wasn't as helpful as I hoped. The fact that you still see the error makes me think that it is not remote fetching but more so a memory issue, but more testing needed to verify.

Here's a simple userscript for testing :

// ==UserScript==
// @name        iosTest
// @description only for testing on ios
// @include     https://www.k21p.com/
// @run-at document-start
// @noframes
// ==/UserScript==

alert("iosTest");
quoid commented 2 years ago

After many hours spent today I still have no clue what is causing these errors. I just did a video call with a friend and we went from fresh install to usage and while we encountered the issue, overall the extension seemingly worked as intended (and this was with a build that re-enabling updated and remote fetches).

We did have to jump between selected folders, one with many scripts another with only, but not perceivable failure pattern could be observed. When we ended the call, the folder that was originally giving us something went wrong was working.

I'm at a real loss as to what is going on here, but will continue to investigate. I truly appreciate everyone who is helping out with the testing.

willl commented 2 years ago

Can confirm similar issues. When I cleared out some larger scripts, it seemed to work fine.

The simple userscript you posted worked fine on both iPhone and iPad.

Haven't had time to try other scripts yet, but will do when I have time.

a9eelsh commented 2 years ago

@quoid Great news! No more error! I believe you were right the first time -- it's most likely a memory issue. There was a rather large userscript (1.1MB) in the original folder I've been trying to use. After trying with a new folder and a smaller test user script (9KB) the error is gone. I don't believe whether I had undownloaded files in my iCloud downloads folder seemed to make a difference, but I emptied it just in case.

I also was able to get it to load by using a very small single file in a directory by itself. https://openuserjs.org/scripts/mscarchilli/Amazon_Smile_Redirect E42EA60D-0A3A-4E54-B95E-4E36133C2215

It is not actually executing the script as I am still on www.amazon.com, but it's a start.

Unfortunately, if I switch directories back to the one with several scripts, "Something went wrong" with no numerical code. I also tried another single js file, it fails for that too. For reference, this is another I am testing with. https://github.com/SteppoFF/ita-matrix-powertools/

I tested it and it works fine for me

a9eelsh commented 2 years ago

Update 1

i’m try two scripts

Script 1 `function betterttv() { const script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://cdn.betterttv.net/betterttv.js'; const head = document.getElementsByTagName('head')[0]; head.appendChild(script); }

betterttv(); `

Script 2 (function betterttv() { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://cdn.betterttv.net/betterttv.js'; var head = document.getElementsByTagName('head')[0]; if (!head) return; head.appendChild(script); })()

The first works fine, but second doesn't

Update 2

I have been using the app for about 8 hours and everything is working fine

quoid commented 2 years ago

@a9eelsh

The first works fine, but second doesn't

Change second code to:

;(function betterttv() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://cdn.betterttv.net/betterttv.js';
    var head = document.getElementsByTagName('head')[0];
    if (!head) return;
    head.appendChild(script);
})();
bradenglund commented 2 years ago

@bradenglund

It is not actually executing the script as I am still on www.amazon.com, but it's a start.

I downloaded the first Amazon Smile script and it was executing, but the code was made for the desktop site. This element: document.getElementById('nav-tools'); is required for the script to redirect and it doesn't exist on the mobile site.

with no numerical code

I removed the numerical code in the latest build as it wasn't as helpful as I hoped. The fact that you still see the error makes me think that it is not remote fetching but more so a memory issue, but more testing needed to verify.

Here's a simple userscript for testing :

// ==UserScript==
// @name        iosTest
// @description only for testing on ios
// @include     https://www.k21p.com/
// @run-at document-start
// @noframes
// ==/UserScript==

alert("iosTest");

So I was able to test with this and it works fine in a directory by itself. It also works if I have either one of these two scripts in the same directory, but not both. https://github.com/AdguardTeam/PopupBlocker https://openuserjs.org/scripts/mscarchilli/Amazon_Smile_Redirect

I played around with a couple of the other scripts, and those all caused Something went wrong as well.

quoid commented 2 years ago

@bradenglund

Thanks for letting me know. I am still lost. Perhaps it has to do with file size and a memory limit?

Yesterday @kfatehi and I were able to do a fresh install on his iphone with all features enabled (@require, @updateURL, etc...) and we did encounter the something went wrong error, but were able to circumvent it by juggling the read directory. At one point he had 22 userscripts in the directory with no errors.

The errors just seemed random. For example, at one point, anytime we put a specific userscript in the folder, the error would appear - so we removed it. Then when we put that userscript back in the folder, the error did not appear. We gained no valuable clues as to what was going on.

For me, most of my userscripts are self-made and quite succinct, which I wonder may be the reason I have no experienced as many issues as others. Whereas userscripts from outside authors tend to be larger to accommodate many users.

So right now I feel no closer to figuring this out than I did a week ago, but I think there are ways to get closer.

If anyone can help figure out the source of this error: https://developer.apple.com/forums/thread/691389

If anyone knows how to monitor memory usage in Safari Web Extensions, please let me know

If anyone has experience with iOS development and is willing to do a code review, email me

If you are encountering the error and want to screen share to look patterns, email me

Outside of that I will keep throwing darts

quoid commented 2 years ago

We have good and bad news.

The good news is that I found the problem!!! I am mad I missed this earlier. It took hours of looking through the logs and it was right under my nose (unfortunately not listed as a fault or error 🙂)

The bad news is that until iOS 15.1 is released there will be issues.

It's a memory limit issue:

Screen Shot 2021-10-17 at 2 09 12 PM

This why is works sometimes and does not for others times.

I guess we have a few weeks to wait.

¯_(ツ)_/¯

v7rzlhb3xg commented 2 years ago

Amazing news! Userscripts has been working flawlessly for me with the couple small scripts I’ve been using. Really impressed, this is an absolute game changer for my iPad. Thank you so much for all of your hard work!

Kartik-715 commented 2 years ago

Hi @quoid, Have we run out of the slots for the number of people who can test? I filled the form yesterday and still haven't got the email to sign up.

quoid commented 2 years ago

Hi @quoid, Have we run out of the slots for the number of people who can test? I filled the form yesterday and still haven't got the email to sign up.

@Kartik-715

I stopped sending out the invites because of the memory issues. The extension kind of works depending on how many scripts there are but it's not very reliable at the moment.

If you still want me to add you I will but keep that in mind if it doesn't function well. Just reply here if you want me to send it.

dslusser commented 2 years ago

Hi @quoid, Have we run out of the slots for the number of people who can test? I filled the form yesterday and still haven't got the email to sign up.

@Kartik-715

I stopped sending out the invites because of the memory issues. The extension kind of works depending on how many scripts there are but it's not very reliable at the moment.

If you still want me to add you I will but keep that in mind if it doesn't function well. Just reply here if you want me to send it.

@quoid I'd like to get in on that too, even considering the issues that are still present. I can lend a hand (albeit amateur hand) troubleshooting.

cynix commented 2 years ago

Hi @quoid, I’d love to help test this as well but it seems the form is now closed. Are you no longer accepting new testers? (I’ve read though this thread and am aware of the memory limitation issues.)

quoid commented 2 years ago

@cynix I re-opened the form, although unless I am specifically asked (like you did) I won't be sending out invites to people until 15.1 is released. I don't people to encountered the issues unless they are well aware (like you are).

If you signed up and email me (email in profile), I will add you.

quoid commented 2 years ago

iOS 15.1 was released today so I opened everything back up for testing. Initial results on my devices seemed promising. Keep feedback coming, you can leave it here in GitHub or email me directly (email on profile page).

Thank you all

cynix commented 2 years ago

It seems a script doesn't work if it starts with an anonymous function. For example (metadata comments omitted for brevity):

Works (alert shown):

alert('test1');

Works (alert shown):

'use strict';

(function() {
        alert('test1');
})();

Works (both alerts shown):

alert('test1');

(function() {
        alert('test2');
})();

Doesn't work (no alerts at all):

(function() {
        alert('test1');
})();
(function() {
        alert('test1');
})();

'use strict';
(function() {
        alert('test1');
})();

alert('test2');
quoid commented 2 years ago

@cynix can you try throwing a semi colon before the anon function? Especially if the code block starts with the anon func. Let me know if this resolves it. If so I think I know where the bug is in the code see.

;(function

Side note any userscript code is already wrapped in an anon function before injection: https://github.com/quoid/userscripts/blob/v4.0.0/extension/Userscripts%20Extension/Resources/content.js

You can see the inject function in the link and also where I think I see the bug

cynix commented 2 years ago

Yep that worked. And I can see what you mean as well, since the content of GM (const GM = ...) doesn't end with a semicolon, it could mess up what follows, right?

quoid commented 2 years ago

@cynix yeah I think that's it

willl commented 2 years ago

Upgraded to iOS 15 and tried a more complex 1.1 MB user script and it worked on both iPhone and iPad.

Kartik-715 commented 2 years ago

Just started using it and all my old scripts work flawlessly!

Thank you for your work! Will keep testing and give you any relevant feedback!

mushidaoren commented 2 years ago

Does not read element content

setTimeout( function(){ var str = document.querySelector('body > div.container > div.header > div > div:nth-child(11) > a').innerText;

var stg = new SpeechSynthesisUtterance(str);

window.speechSynthesis.speak(stg);

}, 5* 1000 );

quoid commented 2 years ago

@mushidaoren

Can you make a new ticket for that issue and I can try to help you with it? It only seems tangentially related to ipad/ios and more of a general userscript issue.

elh-rotem commented 2 years ago

Just tried to do a simple alert on YouTube, it does work, but not if YouTube is opened as a Home Screen shortcut. Seems like a bug to me.

quoid commented 2 years ago

@elh-rotem please post the userscript (even if simple) and steps to reproduce, including device, and os version. I'm not sure what a Home Screen short cut is.

On mobile sometimes pages are cached and do not reload when opened. I am not saying that is the issue here but important to keep that in mind. If that's the cause, often the solution is with the userscript code.

elh-rotem commented 2 years ago
// ==UserScript==
// @name        iosTest
// @description only for testing on ios
// @include     https://www.youtube.com/
// ==/UserScript==

alert("iosTest"); 

Using iOS 15.1 on iPad Pro 11” 2021. There’s an option on Safari to add to the Home Screen a shortcut to a specific site.

quoid commented 2 years ago

@elh-rotem

// @include https://www.youtube.com/

If you're visiting youtube on an iOS device via Safari, iPad or iPhone, you are redirected to https://m.youtube.com. You'd have to update that @include value.

elh-rotem commented 2 years ago

@quoid Tried what you’re suggesting, Issue still persist.