Reddit-Enhancement-Suite icon indicating copy to clipboard operation
Reddit-Enhancement-Suite copied to clipboard

Safari Support

Open benmcgarry opened this issue 4 years ago • 16 comments

So Apple just announced the adoption of WebExtensions API in macOS Big Sur. Please use this issue to track information on what we know as well as test results.

What we know

  • Extensions must be delivered via the App Store. Meaning the $99 is still required and we cannot deliver another way. Still subject to the review process.

  • A converter is used to make a XCode project containing the Web Extension, So a Mac is required for this process.

  • We do not have parity with other browsers for the Web Extensions API, see here.

Documentation

  1. Assessing Your Safari Web Extension’s Browser Compatibility
  2. Converting a Web Extension for Safari
  3. Browser support for JavaScript APIs

Unsupported/Incompatible Web Extension APIs

  • identity (Not supported at all)
  • downloads (Not supported at all)
  • history (Not supported at all)
  • unlimitedStorage (Capped at 10MB)
  • i18n (Limited support, missing API we rely on)

Build Instructions

  1. Install XCode 12
  2. Install XCode 12 CLI Tools
  3. Set to use 12 CLI Tools with "sudo xcode-select -switch /Applications/Xcode-beta.app"
  4. git pull https://github.com/honestbleeps/Reddit-Enhancement-Suite.git
  5. yarn
  6. cd Reddit-Enhancement-Suite
  7. yarn build chrome
  8. xcrun safari-web-extension-converter ./dist/chrome
  9. Follow through steps, can be left at default.
  10. Debug in XCode and off we go!

Tests

First test failed. Extension is enabled in browser however fails to load. The following and only error is displayed in console. Failed to load resource, The operation couldn't be completed (Cocoa error -1000)

Second test failed. Got some more errors, it fails on i18n here with the following error: Unhandled Promise Rejection: ReferenceError: Can't find variable: requestIdleCallback. as well as Failed to load resource, The operation couldn't be completed (Cocoa error -1008)

Note: Unsupported API blocking here.

benmcgarry avatar Jun 22 '20 18:06 benmcgarry

See also https://www.reddit.com/r/Enhancement/comments/hdxq52/so_will_you_bring_back_safari_support_now/

creesch avatar Jun 22 '20 18:06 creesch

not actually tested, just based on my reading of these docs, a few things that may cause issues for RES features in Safari... Docs: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Browser_support_for_JavaScript_APIs

Issues:

  • downloads API support (lack thereof) - no naming images after title on download, I think?
  • events support - not sure if this immediately impacts RES or not without reviewing the code, but noting it because it's severely lacking
  • history support - lack of history support will mean no marking links "read" in Safari
  • incognito support - lack of incognito support means possibly not being able to enable RES in private browsing mode
  • identity support - I'm wild guessing here as I didn't implement the google drive / other backup support, but might this prevent saving settings to cloud storage services?
  • pageAction - no hide support means subreddit CSS toggle icon (toolbar button) might appear even when not browsing reddit

By no means do I feel this is exhaustive, it's just a first pass at things that stick out that I know we use in RES that might be issues for certain features.

honestbleeps avatar Jun 22 '20 22:06 honestbleeps

The missing APIs do not seem to be too big an obstacle:

identity

Chrome does not currently use this API due to some cookie problem.

downloads (Not supported at all)

Only used for showImages, not a big loss - easy workaround. Old Edge also lacked this.

history (Not supported at all)

In addition to what honestbleeps mentions, Safari will also lack the the isRead filter. Though this also didn't work in the old Edge.

unlimitedStorage (Capped at 10MB)

Likely very few that have that much in storage. We could add a module which forces pruning of caches when this limit is hit.

i18n (Limited support, missing API we rely on)

We use requestIdleCallback which is easily polyfillable (this was also the case for Firefox a few versions ago).

larsjohnsen avatar Jun 23 '20 16:06 larsjohnsen

We will end up wasting time trying to get polyfills in when a limited amount of us can actually test this. My opinion right now is to hold off until they mature the API landscape. It was a PITA adding in polyfills for Edge and removing them all and unifying the code was a big project. Adding them back feels dirty. We would also need to decide how updates are handled as it would be a manual process.

benmcgarry avatar Jun 23 '20 18:06 benmcgarry

@larsjohnsen Realistically, how much polyfill do you think would be required? Like would it be possible to polyfill with a separate js loaded in to prevent heavy code change?

benmcgarry avatar Jun 24 '20 13:06 benmcgarry

So: exciting news on the Safari extensions front! macOS Big Sur beta 2 was just released yesterday, and as I was reading through the release notes, I noticed this line:

Support for Web Extensions is now available. Existing Chrome and Firefox extensions can be converted for Safari using xcrun safari-web-extension-converter and distributed through the App Store for use in Safari 14. (55707949)

Needless to say, I immediately got excited and tried it out for myself, using a bunch of different chrome extensions as tests, and long story short, I've gotten to a point where I now have RES running as an extension in Safari 14! (v5.2.2; the latest release had some issues but are most likely easily fixable). So far I've tested this new conversion tool out with Imagus, Lovely Forks, and Cloud to Butt as well, and all work (mostly) perfectly! This could be huge for RES on Safari. I'm going to spend more time playing around with trying to get the latest version to work, will update if I get it working!

Screen Shot 2020-07-08 at 4 18 57 AM Screen Shot 2020-07-08 at 4 19 32 AM

ShotSkydiver avatar Jul 08 '20 10:07 ShotSkydiver

i18n (Limited support, missing API we rely on)

We use requestIdleCallback which is easily polyfillable (this was also the case for Firefox a few versions ago).

FYI: In Safari 14 at least, there's an optional Experimental Feature toggle to enable requestIdleCallback.

Screen Shot 2020-07-08 at 4 14 03 AM

ShotSkydiver avatar Jul 08 '20 10:07 ShotSkydiver

The version of RES you are testing is extremely old. v5.2.2 was released in December 2016 and is no longer a real representation of the RES code base as its gone through extensive changes (This was also the last codebase that had Safari compatibility inside). That release was actually prior to RES adopting webextensions. The latest release of RES needs lots of polyfills to even load into Safari due to poor API support.

At this time we are not really going to progress support until Big Sur releases and we will re-evaluate if we can/want to support the browser.

benmcgarry avatar Jul 08 '20 12:07 benmcgarry

Extensions must be delivered via the App Store. Meaning the $99 is still required and we cannot deliver another way. Still subject to the review process.

Then how does adguard offer a direct download from their site? https://adguard.com/en/adguard-mac/overview.html

unbeatable-101 avatar Oct 04 '20 02:10 unbeatable-101

@unbeatable-101 there's far more to this than the release process, but I'll try and summarize as succinctly as possible:

  1. there was once tons of Safari-unique code in RES because of its various quirks, differing API functionality, etc. That has since been removed (now years ago) since support was dropped and it was extra work to maintain and test separate code on another browser for every release.

  2. The new support Safari has for chrome extension APIs is actually VERY limited. Many features of RES would not work on Safari even if we supported it, because its API support is fairly limited. This may become less true over time, but it is true for now.

  3. RES is used by millions of users, and therefore being able to push automatic updates to users is critical to us in order to minimize support requests, increase users' satisfaction (through prompt bug fixes, etc), and also to ensure that any security updates are pushed out in a timely manner. Last I checked, self-hosting, as Adguard does, does not allow for automatic updating.

  4. Beyond the above, it's also significant extra work to build for Safari, as xcode is required, etc. First we must own macs just to build/test it - not everyone can afford the expensive hardware. Next, a certain amount of extra work is required for every build, and for every test -- so even if we have macs (not all contributors do), it's significant extra overhead to support Safari.

We will continue to watch as Safari's support hopefully improves, and we may revisit supporting it at some point - but at this point, attempting to convince us we're wrong not to support it isn't really helpful. What would be helpful is if someone wants to dedicate time to contributing to its support. I'd consider paying the fee and putting it into the extension gallery IF we can get adequate support not only from Apple and Safari's APIs, but from some number of developers willing to continue supporting it over time - because every time we release new features, bug fixes, etc, they have to be tested across yet one more browser - adding overhead to every release.

TL;DR: it's just not as simple as "you guys are being [stubborn|objectionable|lazy|contrarian] for not supporting Safari".

honestbleeps avatar Oct 04 '20 04:10 honestbleeps

I knew you guys weren’t just being lazy, I was just wondering about the adguard part. Thank you for the answer

unbeatable-101 avatar Oct 04 '20 11:10 unbeatable-101

It looks like AdGuard for Mac is an actual OSX application, which apple allow you to host and provide download. However for Safari extensions Apple strictly require them to only be available via the store.

benmcgarry avatar Oct 04 '20 11:10 benmcgarry

Refined Github went the route of building an .app and loading it by enabling "Allow Unsigned Extensions" - https://github.com/sindresorhus/refined-github/issues/14

I think RES could probably do something similar

dvcrn avatar Dec 02 '20 08:12 dvcrn

according to the latest comment on that thread, users will have to build it locally, so it's still a pretty unfriendly method... See here: sindresorhus/refined-github#14 (comment)

and there's still the matters of:

  • Safari's API doesn't support all webextensions APIs we'd want for RES
  • Safari's unique bugs we'd have to seek out and put fixes back in for - it was always the browser that required the most custom, browser-specific code to avoid issues

The workload still outweighs the benefits at this point, probably.

honestbleeps avatar Dec 02 '20 17:12 honestbleeps

I'd love to help porting this but I'm not so familiar with this repository. Do you have a summary by chance which APIs aren't supported that RES needs that Safari doesn't support yet?

dvcrn avatar Dec 03 '20 08:12 dvcrn

@honestbleeps Maybe https://redditenhancementsuite.com/contribute/ could be updated to have an option/callout where the donation is marked specifically towards helping support Mac & Safari development.

Help fund/support:

  • Having an active Apple developer account subscription
  • Have necessary hardware (be it an M1 Mac Mini or a refurbished Mac to keep costs at a minimum if nobody with dev involvement has access to a Mac currently)
  • Added development time
  • etc.

Missing out on this extension outright is something some people might be willing to chip in on to help get it there if the dev team doesn't naturally expand to include Mac development and/or Mac-based contributor(s).

That could also promote awareness that you know people want it & could bring in untapped support (be it monetary and/or developer support.)

KZeni avatar Mar 08 '21 18:03 KZeni