userscripts icon indicating copy to clipboard operation
userscripts copied to clipboard

iOS + iPadOS Support

Open Kartik-715 opened this issue 5 years ago • 126 comments

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!

Kartik-715 avatar Jun 08 '21 08:06 Kartik-715

@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.

quoid avatar Jun 08 '21 13:06 quoid

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!

Kartik-715 avatar Jun 08 '21 13:06 Kartik-715

@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.

quoid avatar Jun 08 '21 13:06 quoid

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?

Reinachan avatar Jun 22 '21 17:06 Reinachan

@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.

quoid avatar Jun 22 '21 17:06 quoid

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?

Reinachan avatar Jun 22 '21 17:06 Reinachan

@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!

quoid avatar Jun 22 '21 18:06 quoid

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 :/

Reinachan avatar Jun 23 '21 21:06 Reinachan

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 avatar Jun 23 '21 21:06 quoid

track progress here:

#145

https://github.com/quoid/userscripts/milestone/6

https://github.com/quoid/userscripts/tree/v4.0.0

quoid avatar Jul 08 '21 03:07 quoid

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 avatar Aug 12 '21 01:08 quoid

@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 👍

julianpomper avatar Sep 17 '21 10:09 julianpomper

@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 avatar Sep 17 '21 13:09 quoid

@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.

quoid avatar Sep 17 '21 13:09 quoid

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

julianpomper avatar Sep 17 '21 13:09 julianpomper

@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.

quoid avatar Sep 18 '21 20:09 quoid

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?

EthanG45 avatar Sep 21 '21 10:09 EthanG45

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".

quoid avatar Sep 21 '21 13:09 quoid

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.

EthanG45 avatar Sep 22 '21 21:09 EthanG45

Hopefully, one day userscripts can come to iOS still.

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

quoid avatar Sep 23 '21 02:09 quoid