Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS + iPadOS Support #135

Closed
Kartik-715 opened this issue Jun 8, 2021 · 126 comments
Closed

iOS + iPadOS Support #135

Kartik-715 opened this issue Jun 8, 2021 · 126 comments
Assignees
Milestone

Comments

@Kartik-715
Copy link

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!

@quoid
Copy link
Owner

quoid commented Jun 8, 2021

@Kartik-715

I have to read more about the support. It seems like Apple is supporting Safari WebExtensions in iOS, not Safari App Extensions. This extension is an App Extension not a Web Extension.

If that is the case the extension would need to be re-written and current functionality could be lost. At the current time I do not know.

@Kartik-715
Copy link
Author

Ahh I see! Anyway I'm going to try and migrate the extension from app extension to web extension! Let's see if that's possible!

@quoid
Copy link
Owner

quoid commented Jun 8, 2021

@Kartik-715 It is possible it's just a matter of time and rewriting certain functionality like interacting directly with the file system. I don't have any doubts it is possible.

I am waiting until more information is out about the new iOS 15 features before I make any plans. However, once I hear more I will likely be re-writing, so I would suggest not to waste your time attempting to migrate anything. If you want to help when I begin the rewrite that would be more beneficial to the project.

@Reinachan
Copy link

You implement Safari web extensions as macOS or iOS app extensions to provide a safe and secure distribution and usage model. You can distribute a Safari web extension with a Mac app, an iOS app, or a Mac app created using Mac Catalyst. You must use Xcode to package your extensions for testing in Safari, and you must be a member of the Apple Developer Program to distribute them through the App Store. For more information, see Apple Developer Program.
https://developer.apple.com/documentation/safariservices/safari_web_extensions

Looks like Safari App Extensions and Safari Web Extensions will work on iOS?

@quoid
Copy link
Owner

quoid commented Jun 22, 2021

@Reinachan

Looks like Safari App Extensions and Safari Web Extensions will work on iOS?

I read the quote, but can you elaborate on why you think Safari App extensions will work? Specifically app extensions without WebExtension components.

@Reinachan
Copy link

Ah, without web extension components. Well, then I wouldn't know. I added a questionmark to it as the wording by Apple was a bit vague.

Looking deeper into the various documentation pages, it looks like it's Safari Web Extensions but with the ability to have a native app to control it from.

It also looks to me like they're moving away from Safari App Extensions in general and toward Web Extensions instead. Might be worth considering refactoring to Web Extension either way, as they might just end up cutting support for Safari App Extensions down the line. Who knows.

Moving to Web Extensions could also have the advantage of making it much easier to enable using the extension in other browsers too from what I can gather?

@quoid
Copy link
Owner

quoid commented Jun 22, 2021

@Reinachan

Thanks for the clarification. I agree that migrating to Web Extension will prove valuable and that is my goal, however I can not give a firm estimate on when that will be complete as it is will take some time.

That being said, simply converting to being predominately WebExtension API won't instantly enable usage in iOS as there are other aspects of the extension to consider, such as selecting the "scripts folder" and mobile considerations for the extension page (ie. editor which will likely barely function on any mobile device currently).

It also looks to me like they're moving away from Safari App Extensions in general and toward Web Extensions instead. Might be worth considering refactoring to Web Extension either way, as they might just end up cutting support for Safari App Extensions down the line. Who knows.

Once they announced WebExtensions, I had the same thought. It's already sort of happening since the WebExtension API is much more robust compared to the App Extension API (which gets seldom updates). It does slightly irk me that Apple decided to drop Safari JS Extension API and force users into App Extension API only to (a few years later) seemingly begin abandoning App Extension API in favor of WebExtension API. It's better for the browser but reveals their finicky and haphazard forward thinking (in terms of Safari).

Moving to Web Extensions could also have the advantage of making it much easier to enable using the extension in other browsers too from what I can gather?

Very true, however at the current moment I don't have much interest in adding additional browser support since there are really good options for those browsers. But that opinion could change in time.

Anyway, WebExtension refactor is planned, stay tuned!

@Reinachan
Copy link

You've got some good points in regards to an iOS port. I think that for an initial release, simply giving the option to add/remove userscripts/styles you find on the web could be enough, and potentially expand upon it later.

Personally, I just want to use the userstyles I write on my PC on iOS for instance, and I will assume that a majority of people who use plugins like this don't write them themselves.

I don't know what APIs they give you access to, but considering they let you add a native app to control certain stuff in the extension, perhaps you also get access to a folder in the filesystem which you can store things in? In that case, you might not even need some way to write them, as users could just write them in their preferred program and add it to that folder?

I'd contribute to this but my Macbook decided that it no longer wants to boot regularly (only if in safemode), so I had to install Linux on it to even be able to continue using it. Means I won't really be able to test anything or deploy it to my iPad :/

@quoid
Copy link
Owner

quoid commented Jun 23, 2021

I don't know what APIs they give you access to, but considering they let you add a native app to control certain stuff in the extension, perhaps you also get access to a folder in the filesystem which you can store things in? In that case, you might not even need some way to write them, as users could just write them in their preferred program and add it to that folder?

I think that would exactly what I'd want to see in a v1 for iOS - simply the ability to read userscripts from a directory of the user's choosing. For example, I store all my scripts in an iCloud folder, if I am able to read from that directory and utilize the userscripts located there, on my phone, I would be very pleased.

Long term possibilities are endless, but I am fairly certain that creating an editor for iOS or iPadOS is more than likely not a goal.

I'd contribute to this but my Macbook decided that it no longer wants to boot r

You already are contributing by sparking up conversation and it's valuable!

@quoid quoid changed the title iPadOS Extension iOS + iPadOS Support Jul 1, 2021
@quoid quoid self-assigned this Jul 1, 2021
@quoid quoid added this to the Version 4.0 milestone Jul 1, 2021
@quoid quoid closed this as completed Jul 8, 2021
@quoid quoid reopened this Aug 12, 2021
@quoid
Copy link
Owner

quoid commented Aug 12, 2021

This is still being investigated. I am unsure how to go about configuring the project to support iOS. Apple suggests using a converter to add support for other platforms, but unfortunately the converter does not seem to run properly on my computer.

For example, running:

xcrun safari-web-extension-converter --rebuild-project /path/to/project.xcodeproj

Doesn't do anything but display the help text for the converter.

If anyone knows how to add support please send me a message. My email is on my profile page.

@quoid quoid pinned this issue Aug 12, 2021
@julianpomper
Copy link

julianpomper commented Sep 17, 2021

@quoid I think I found your issue. The problem is that the --rebuild-project option is just available with the Xcode 13 developer tools. So if you run xcrun but did not change the active development directory to the Xcode 13 tools it does not find this option.

You can try entering sudo xcode-select -s path/to/Xcode.app (path to Xcode 13, you can change it back later). Now the command xcrun safari-web-extension-converter --rebuild-project /path/to/project.xcodeproj should work 👍

@quoid
Copy link
Owner

quoid commented Sep 17, 2021

@julianpomper I had tried that in the past and just tried it again this morning and the results are the same. The converter does not do anything but print out help text. Interestingly the help text does not state that --rebuild-project is a valid option.

Have you successfully rebuilt an existing macIS webextension? If so, what OS are you on and Safari version? I am using Safari 14.1.1 and macOS 11.4 and just figured the tool wasn't available fully until the next macOS.

Screen Shot 2021-09-17 at 8 57 48 AM

@quoid
Copy link
Owner

quoid commented Sep 17, 2021

@julianpomper

option is just available with the Xcode 13

I re-read your post and realized I am on Xcode 12... Sorry it is early for me 🙂

I reckon I won't be able to covert and build the iOS side until I am on the new macOS (or download Xcode Beta). When that gets released I should be able to update and run the convertor and start that process.

@julianpomper
Copy link

julianpomper commented Sep 17, 2021

Exactly you should already be able to do that now with macOS 11.4. Download the Xcode 13 RC here in the Beta tab. After that open it once and install the additional tools. If that is done you should be able to do the steps I described above:

You can try entering sudo xcode-select -s path/to/Xcode.app (path to Xcode 13, you can change it back later). Now the command xcrun safari-web-extension-converter --rebuild-project /path/to/project.xcodeproj should work

Edit: and of course open the Xcode project with Xcode 13 from now on 😄
Edit2: I think this can be also helpful: https://developer.apple.com/documentation/safariservices/safari_web_extensions/optimizing_your_web_extension_for_safari

@quoid
Copy link
Owner

quoid commented Sep 18, 2021

@julianpomper I just wanted to give you an update. The good news is that I was able to convert the extension to iOS 🎉

The bad news is that a good deal of the v4.0.0 code needs to be re-written #if os(iOS). This will likely take a long time unless I can find an experienced iOS developer to help with this.

@EthanG45
Copy link

What do you mean rewritten? Coming in here with no context just interested in seeing any user script app reach iOS. Do you mean the scripting code no longer works or just UI is broken?

@quoid
Copy link
Owner

quoid commented Sep 21, 2021

What do you mean rewritten?

@EthanG45

Here's some examples:

  • Currently the app uses security scoped bookmarks, which are set by the user through the containing app, to set the read/write location. The way this is written in macOS is not comptatible with iOS.
  • By default the app reads from the users .documentsDirectory, but for the iOS version there'd have to be a specific workflow which compels the user to set a shared folder as a read location. Creating userscripts is not in the scope for the iOS version.
  • When converting the extension is does not keep any of the swift functionality that is included in the current and beta versions. That needs to be integrated back in after the conversion, or better yet, the conversion needs to happen, then that converted version needs to be integrated into the current project (or some similar approach).

Anyway, my point is there's a lot of stuff that needs to get to done to even figure out if it is viable to run on iOS and iPadOS (I think it will). Some of that includes iOS development which I am inexperienced with. If all of this is left up to me, it will probably get done, but just take quite a while.

Do you mean the scripting code no longer works or just UI is broken?

I reckon it's mostly UI but some of the scripting code needs to be adapted. As mentioned above about the file read location - that is at the core of how userscript injection works. But most of the injection core happens on the WebExtension side which seems supported according to the documentation.

Also note that the iOS parts seemingly can co-exist with the macOS. So it's really more about created some iOS specific code rather than a "rewrite".

@EthanG45
Copy link

Ah I see that is a lot of non-easily converted code. I've got some naive iOS experience mostly on the UI side, so I can't say I could contribute much, at least right now I've got a full plate. Hopefully, one day userscripts can come to iOS still.

@quoid
Copy link
Owner

quoid commented Sep 23, 2021

Hopefully, one day userscripts can come to iOS still.

It might take a little bit but I think it will get there @EthanG45

@quoid
Copy link
Owner

quoid commented Oct 2, 2021

Update

I've been running some tests. Outside of adapting current code to work on iOS, I am still in the process of figuring out if choosing a read location can persist between Safari launches. Choosing a location for reading the userscripts will have to be done as it is currently done in the current macOS app. That means the user selects this location in the containing app, in this case the iOS app and then a sharedbookmark is created and stored in a shared userdefaults file.

That shared userdefaults value is then read by the extension. In the simulator, it seems like this persists, but I am unsure how this will function on an actual phone/ipad. I've read some random forum posts suggesting that it is not possible to have sharedbookmarks persist as they can in macOS. If that is true, I am not sure how to approach all of this. However, it seems to persist currently, so I am hoping it is not true.

Once that is figured out, I think the path is clear. I'm successfully running this in the simulator currently.

Screen Shot 2021-10-02 at 11 01 48 AM

Screen Shot 2021-10-02 at 11 02 05 AM

@EthanG45
Copy link

EthanG45 commented Oct 2, 2021

@quoid That's fantastic to hear! Looking forward to future updates on development progress.

@quoid
Copy link
Owner

quoid commented Oct 3, 2021

Update

I updated my iPhone 8 to ios 15 and loaded the extension. Injection seems to occur, will update everyone on if the bookmark persists. However, the popup does not load properly. This is not something I experienced in the simulator.

I made a thread in the Apple forums in hopes of deciphering the error code: https://developer.apple.com/forums/thread/691389

If anyone has any insight please post here

@quoid
Copy link
Owner

quoid commented Nov 14, 2021

@vjjj4688

I tried to download several scripts in the happy fork

What is happy fork?

Is you having an issue with the new version of the app or the old? This is easy to tell by the current build number, which is shown in the iOS app, example -> v0.1 (x)

@vjjj4688
Copy link

sorry,https://greasyfork.org/,I mean this script download website,I am using the latest version of 0.1 (2),It doesn't work like previous versions

@quoid
Copy link
Owner

quoid commented Nov 14, 2021

@vjjj4688

Thanks for the clarification.

It doesn't work like previous versions

That is odd, it is the same app with a different bundle id. However things could have gotten messed up since the old version uses a similar app.group container.

Please try the following:

  • Make sure you deleted the other version of the app
  • Ensure the proper directory is showing in the iOS app
  • Re-select the directory in the iOS (choose it again after hitting the blue button)
  • Make sure the new extension has the proper permissions (In settings go to Safar i > Extensions > Userscripts)
    • it should be allowed on all website always

If you are certain these scripts were all working in the previous version and you have checked the above, you can delete the new version and re-install and continue to use the old version that was working for you while I wait to see if this is an issue with everyone or just you.

I will not invalidate the old version until I am sure others are able to use the new version in the same way they used the old version.

@vjjj4688
Copy link

@vjjj4688

Thanks for the clarification.

It doesn't work like previous versions

That is odd, it is the same app with a different bundle id. However things could have gotten messed up since the old version uses a similar app.group container.

Please try the following:

  • Make sure you deleted the other version of the app

  • Ensure the proper directory is showing in the iOS app

  • Re-select the directory in the iOS (choose it again after hitting the blue button)

  • Make sure the new extension has the proper permissions (In settings go to Safar i > Extensions > Userscripts)

    • it should be allowed on all website always

If you are certain these scripts were all working in the previous version and you have checked the above, you can delete the new version and re-install and continue to use the old version that was working for you while I wait to see if this is an issue with everyone or just you.

I will not invalidate the old version until I am sure others are able to use the new version in the same way they used the old version.

sorry,I used translation software, so you may have misunderstood what I meant,I mean, the last version and this version, they both do not work properly,I can see the script in the address bar of safari,But it doesn't actually run successfully,I'm sure I've given all permissions and the script is fully available on the pc
Uploading FC2F31E2-610C-408E-83E7-35AEFAFC96DE.png…

@vjjj4688
Copy link

Uploading 245238FF-78A5-4FCE-99D1-46CB07F85B38.png…

@quoid
Copy link
Owner

quoid commented Nov 14, 2021

@vjjj4688

Thank you for the additional clarification. I see you are trying to upload an image, but it does not appear to be displaying.

Since you are having an issue with both version, I suspect there could be an issue with the file you are trying to run.

As a test, please create a new userscript file with the code below and visit any website. You should see an alert show up:

// ==UserScript==
// @name        iosTest
// @description only for testing on ios
// @match     <all_urls>
// @run-at document-start
// @noframes
// ==/UserScript==

alert("iosTest");

If you do not see this alert on the first try, open the popup and ensure you see it in the list and refresh the page a couple of time.

This is will tell me if your issue is with the app or the javascript file you are trying to execute.

@vjjj4688
Copy link

@vjjj4688

Thank you for the additional clarification. I see you are trying to upload an image, but it does not appear to be displaying.

Since you are having an issue with both version, I suspect there could be an issue with the file you are trying to run.

As a test, please create a new userscript file with the code below and visit any website. You should see an alert show up:

// ==UserScript==
// @name        iosTest
// @description only for testing on ios
// @match     <all_urls>
// @run-at document-start
// @noframes
// ==/UserScript==

alert("iosTest");

If you do not see this alert on the first try, open the popup and ensure you see it in the list and refresh the page a couple of time.

This is will tell me if your issue is with the app or the javascript file you are trying to execute.

After testing, it can work normally,But why can't any of the scripts I'm using myself run successfully? But why can't any of the scripts I use myself run successfully? I can only see them, but they don't work. This is the download address of the script I used,https://greasyfork.org/zh-CN/scripts/14178-ac-baidu-重定向优化百度搜狗谷歌必应搜索-favicon-双列,Maybe you can help me see if there is indeed a problem with the script? After all, I can use it properly on my PC and it's not the only one that has problems, all scripts don't work properly

@vjjj4688
Copy link

@vjjj4688

Thank you for the additional clarification. I see you are trying to upload an image, but it does not appear to be displaying.

Since you are having an issue with both version, I suspect there could be an issue with the file you are trying to run.

As a test, please create a new userscript file with the code below and visit any website. You should see an alert show up:

// ==UserScript==
// @name        iosTest
// @description only for testing on ios
// @match     <all_urls>
// @run-at document-start
// @noframes
// ==/UserScript==

alert("iosTest");

If you do not see this alert on the first try, open the popup and ensure you see it in the list and refresh the page a couple of time.

This is will tell me if your issue is with the app or the javascript file you are trying to execute.

https://greasyfork.org/zh-CN/scripts/14178-ac-baidu-重定向优化百度搜狗谷歌必应搜索-favicon-双列

https://greasyfork.org/scripts/14178-ac-baidu-重定向优化百度搜狗谷歌必应搜索-favicon-双列/code/AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列.user.js

@quoid
Copy link
Owner

quoid commented Nov 14, 2021

@vjjj4688

After testing, it can work normally

This tells me that this is an issue with the file not the extension.

After all, I can use it properly on my PC and it's not the only one that has problems, all scripts don't work properly

Those scripts are likely using features that are not supported with this extension or not targeting mobile versions of the website. There is a language barrier here, but the readme documents what features are currently enabled for this extension.

It's important to note that not all features present in other userscript manager are present in this userscript manager. Sometimes editing of a userscript is needed if you want to use it with this manager.

In the script you linked there is a github repository linked: https://github.com/langren1353/GM_script - it might be valuable to go there and seek help with editing the script.

@vjjj4688
Copy link

Thank you for your patience in answering,I think I know what to do.

@quoid
Copy link
Owner

quoid commented Nov 14, 2021

If you're testing iOS and want to test macOS, please sign up here: #164 - that platform needs more testers

I did not want to spam iOS testers with macOS invites since that's not what they signed up for, so I created a separate form.

Thanks to everyone who is helping to test!

@xinkev
Copy link

xinkev commented Nov 18, 2021

Can I take part in testing on iPadOS?

@quoid
Copy link
Owner

quoid commented Nov 18, 2021

@xinkev sure, if you haven't already, please sign up here: https://forms.gle/QB46uYQHVyCxULue9

@ViRo3
Copy link

ViRo3 commented Nov 19, 2021

This extension is very broken on iPadOS but works well on mac.

Would also be very helpful if it automatically opened links from userscripts sites to load into the app instead of relying on downloading files alone.

@quoid
Copy link
Owner

quoid commented Nov 19, 2021

@ViRo3 Can you elaborate? Saying it is "very broken" doesn't offer much insight into what is going on.

Please provide your device specs, the userscript you are trying, what is the expected behaviour and what you are actually seeing. Also include steps that you took to remedy the issue, if any. Have you ensured the issue isn't caused by the userscript you are trying to execute or potentially user expectations exceeding what is possible? is it a UI issue? etc...

Myself along with others are using it on an iPad successfully, so it is worry to hear that is broken for you.

I understand you might be frustrated because something isn't working as you intend, but I need constructive feedback in order to improve the product.

Can anyone else using this on iPad verify the "very broken" claim?

Would also be very helpful if it automatically opened links from userscripts sites to load into the app instead of relying on downloading files alone.

This is on the radar.

@ViRo3
Copy link

ViRo3 commented Nov 19, 2021

iPad 9. Extension is linked above (MangaLoader).
I absolutely didn’t mean it in any negative way and the app truly works wonders for all my extensions but the attached one above. The issue is it doesn’t load the images of the pages and UI issues are there alongwith non-interactive buttons/no animation, it is expected to load the images along with showing the settings.

it is only applicable for this extension and not any other which the app covers well. Am unaware of whether its the issue of the extension or the app.

PS : it would be very appreciated if the app automatically installed scripts in their respective pages on Greasyfork:Github too.

@quoid
Copy link
Owner

quoid commented Nov 20, 2021

@ViRo3

Thank you for the clarification. I hope my reply didn't seem mean, I think there was some translation issues. What you call "extension," I call a "script" or "userscript". This app is technically an app and extension bundled together. So when you said "This extension is very broken in iPadOS" - I understood that as "The app is very broken."

I now understand you mean that the script file you were trying was broken (or not working).

I believe the issue you are experiencing with this script is because several issues, and one of them is a bug (thank you for reporting this):

  1. The script uses many external libraries that are called @require - however this app is not calling them in the proper order (that is why you can can see errors in the console, image below) - I created a new ticket for this bug here: Keep @require resources in order that they were called when injected #166

  2. This script is using some GM keys that are not currently supported. I do not know if this would cause the functionality to break, but it is good to know. Support for those keys will come at some point, I hope.

Unsupported Keys

// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest

Error in console

Screen Shot 2021-11-19 at 10 32 47 PM

Thank you again for reporting this issue

Repository owner deleted a comment from luxysiv Dec 4, 2021
@Taxyovio
Copy link

Does the @require key work properly?

I’ve not been able to make this Manga Loader NSFW script work. This script is a NSFW add-on to the main script. It uses @require to load the main script.

The interesting part is that the script runs properly when directly used in a bookmarketlet:
javascript:(function(){BM_MODE=true;var addScript=function(src,onload){var s=document.createElement('script');s.onload=onload;s.src=src;document.body.appendChild(s);};addScript('https://greasyfork.org/scripts/692-manga-loader/code/Manga%20Loader.user.js',addScript.bind(null,'https://greasyfork.org/scripts/12657-manga-loader-nsfw/code/Manga%20Loader%20NSFW.user.js'));})();

It also works when it’s merged directly into the main script as this gist.

A safe for work test manga would be https://e-hentai.org/s/5225e47182/2082483-1.

@quoid
Copy link
Owner

quoid commented Dec 12, 2021

@Taxyovio

Can you make a unique issue for this?

That @require url doesn't end with .js so it gets ignored. The @require validation doesn't account for query params. I can look into this. Can you note this in the issue you create for this?

remove the ?29 and it would probably work

Thanks for pointing this out.

@quoid
Copy link
Owner

quoid commented Jan 6, 2022

iOS version 1.0 has been approved and should show up on the app store soon enough. To those of you who helped test this, I really appreciate it and I look forward to continuing to improve the iOS experience.

Please do leave a review on the app store, especially those of you who've been using the iOS app for several weeks :)

Thanks all, I am closing this issue now, merged b8b8a7f

@quoid quoid closed this as completed Jan 6, 2022
@quoid quoid unpinned this issue Jan 6, 2022
@quoid quoid mentioned this issue Jan 10, 2022
@ACTCD ACTCD added this to Tasks Aug 19, 2024
@ACTCD ACTCD moved this to Release in Tasks Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Release
Development

No branches or pull requests