honestbleeps / Reddit-Enhancement-Suite

Reddit Enhancement Suite
http://redditenhancementsuite.com
GNU General Public License v3.0
4.13k stars 881 forks source link

Safari Support #5238

Open benmcgarry opened 4 years ago

benmcgarry commented 4 years ago

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

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

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.

creesch commented 4 years ago

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

honestbleeps commented 4 years ago

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:

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.

larsjohnsen commented 4 years ago

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

benmcgarry commented 4 years ago

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 commented 4 years ago

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

ShotSkydiver commented 4 years ago

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 commented 4 years ago

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
benmcgarry commented 4 years ago

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.

unbeatable-101 commented 3 years ago

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

honestbleeps commented 3 years ago

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

unbeatable-101 commented 3 years ago

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

benmcgarry commented 3 years ago

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.

dvcrn commented 3 years ago

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

honestbleeps commented 3 years ago

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:

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

dvcrn commented 3 years ago

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?

KZeni commented 3 years ago

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

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