Comments (9)
Hi, following the same logic as Daniel’s doc. It could be solved by WKURLSchemeHandler on iOS 11.
But unfortunately, this there is no such API on iOS 10 and older. I am testing other older APIs for possible solution, probably it will require big change in current code.
Here is what I did for iOS 11.
- Support R2InternalScheme, you can get the
R2Internal
scheme url from new my function. I didn't change the old function, so you can still the original url.
https://github.com/iaomw/r2-shared-swift/commit/f4f223371ad6f7dab6901c0ac54575bebf6f74b0 - Add
R2InternalHandler
for our customizedWKWebView
. It will replace theR2Internal
url with original url for anyR2Internal
request, so it could get the content but still has differentorigin
.
https://github.com/iaomw/r2-navigator-swift/commit/05a2238d15455c798fa23c6b422e8f8ab70a81b0
from swift-toolkit.
After my research, I think there are 3 possible ways to solve it on iOS 10 and older:
- Download the web page manually with
URLSession
, then load data with thisWKWebView
function below. It could have a different url, yet different origin.
https://developer.apple.com/documentation/webkit/wkwebview/1415011-load
But here is a problem, theWKWebView
will download other resource (image, css, js) automatically, there is no API to control resource downloading requests iOS.
I foundWebResourceLoadDelegate
, but it's only available on Mac OS.
https://developer.apple.com/documentation/webkit/webresourceloaddelegate - Make separated
WKWebsiteDataStore
for eachWkWebView
. I works fine, but Apple only provides thedefault
shared instance andnonPersistent()
option. If there is a way to do serialization on thenonPersistent()
instance, it will be solved. But it doesn't work.
https://developer.apple.com/documentation/webkit/wkwebsitedatastore - In
JavaScript
, replace thesetItem
andgetItem
fucntions onlocaStorage
. Then call some Swift function inside the new JavaScript functions. As the consequence, I can use any storage solution with Swift. But I am not sure how is the performance. Does it also work with "https"?
from swift-toolkit.
I don't think that these options are viable.
IMO, we shouldn't sacrifice everything else just for the sake of solving the Origin issue.
I would defer this issue for now. cc @llemeurfr
from swift-toolkit.
We are waiting for other inputs; it is currently put on the side.
from swift-toolkit.
I looked at iaomw's code, with WKURLSchemeHandler
, and I think it's probably the cleanest solution we can implement for iOS 11 and newer. The problem is iOS 11 represents only 65% of devices and iOS 10 is still at 28%.
Regarding the alternatives for older platforms proposed by iaomw, my thoughts are:
-
I'm not aware of an API provided by Apple or by a third-party library which makes possible to filter data downloaded by type or something similar. I've made some research but didn't find anything.
Furthermore, i'm not so enthusiastic by the idea of duplicating data (the original web page, then the downloaded one). I'm not sure, but web page size for an EPUB can be huge, right? -
It would be a nice solution, but i'm almost certain it won't be possible to set up. The method
nonPersistent()
is used to reproduce a private browsing feature so I guess there is an inner mechanism in Apple's Webkit implementation to prevent hijacking browsing history when the user think its navigation is private. -
We should be able to implement this one. By intercepting calls to
setItem
andgetItem
we could then, in the native Swift code part, rely on something like UserDefaults to safely read and store data. However, it's a lot of overhead. Regarding the performance issue, maybe someone more experienced with JavaScript could answer to the question. We should know how often are usedsetItem
andgetItem
methods, and we have to find a way to benchmark this alternative implementation oflocalStorage
.
IMO, i would go for the initial solution proposed by iaomw (WKURLSchemeHandler
), keeping compatibility with iOS 9 and 10. As llemeurfr said on Slack, risk of data collision could be mitigated by recommending a best practice to authors (publication-specific prefix).
from swift-toolkit.
Early in this project, we decided that iOS 9.x would be our minimal requirement.
I don't think that we should revisit that decision in this cycle:
- as it's been pointed out, even on devices that can run iOS 11, many users are still using iOS 10
- unlike smartphones, tablets have a longer lifecycle and some very popular models of the iPad are currently stuck with iOS 9.x forever
We can re-open that discussion about the minimum version for a future revision cycle, but IMO we absolutely need to deliver a solid 1.0 version that supports iOS 9.x first.
from swift-toolkit.
I don't see the point linking the minimal iOS version of the app with the version from which we solve this Origin issue. iOS 9 is the minimal version for the R2 SDK, this will not be re-opened. But we can still decide by consensus that, as Apple does not provide a correct API to handle that issue under iOS 11, we'll live with it on older versions and will alert authors on this fact.
from swift-toolkit.
For the time-being, I agree with you @llemeurfr but eventually we'll have to release features that won't be compatible with older version of iOS.
I'm mostly thinking about WP/PWP related features, that will probably require (among other things) Service Worker support.
from swift-toolkit.
will alert authors on this fact
FWIW, I added that to the Blitz’ Design checklist in February as it’s quite critical. Most Android apps don’t handle the origin as expected anyway – maybe there’s nothing to deal with it on this platform – so yeah, there’s definitely an authoring best practice to promote there.
from swift-toolkit.
Related Issues (20)
- Extracting `t` fragment from `Locator` HOT 1
- Larger Text Display Zoom on iPhone: Navigation bar pushes text HOT 3
- Pinning the font size (for <p>, <li>, <div>, etc) HOT 1
- Logger doesn't log above min severity level
- AudioNavigator.seek cannot cross previous resource boundary HOT 10
- When a DRM key error occurs while opening an EPUB, navigator is stuck in loading state HOT 10
- Errors while loading a Resource in GCDHTTPServer are not bubbled up HOT 5
- 'asSQL' is inaccessible due to 'internal' protection level HOT 2
- Name collision caused by GCDWebServer dependency HOT 5
- Error"Error initializing db." HOT 13
- Nondeterministic loading issue with `EPUBNavigatorViewController` HOT 2
- [Feature] Add support for new LCP Profiles
- Logic behind the selected text information for remote server HOT 2
- Pagination after increasing the font size HOT 4
- [Bug] EditingActions like Define Lookup are not shown. HOT 1
- [develop] Locator href for exploded archive audiobook incorrectly starts with leading slash HOT 2
- [develop] Opening exploded archive audiobook inside App Group fails with `Publication.OpeningError.unsupportedFormat` in (Designed for iPad) Mac app HOT 9
- [Bug] Search Result Chapter Title HOT 6
- lcpl file which is pub format can't be open by publication.metadata.identifier is nil HOT 6
- `Navigator.go` results in misaligned view HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-toolkit.