gdnmobilelab / swwebview Goto Github PK
View Code? Open in Web Editor NEWAn experiment in adding Service Worker APIs to an iOS WKWebView
License: MIT License
An experiment in adding Service Worker APIs to an iOS WKWebView
License: MIT License
Without a LICENSE file all the work contained in this repo is considered to have their copyright assigned to the author. Adding a LICENSE file to the repo will help make it easier for others to contribute to this repo.
In the course of writing the README for the project, I found out that ServiceWorkerGlobalScope.skipWaiting()
actually returns a promise... that returns immediately with a value of undefined
:
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
Our version just returns undefined. Should be a pretty simple fix.
I've opened a bug for this: http://www.openradar.me/radar?id=4952053319204864 but so far no replies.
Any POST request coming from SWWebView doesn't have its HTTP body attached. Right now I have a very horrible patch on fetch
that inserts the (string) body as a header before performing the fetch. The native code repatches this to be the actual body so no backend code ever needs to be aware of this, but there are still a lot of issues:
There are some stopgap fixes we could implement:
But they're all pretty awful. Unfortunately the only real fix I can see is Apple fixing the original bug, but depending on how long that takes, we might need to implement some stopgaps. In the more immediate term, we could get some tests going to see what these character limits actually are.
In browsers, you can run text()
, json()
and so on onRequest
, the same as you can Response
, because they both inherit from Body
: https://developer.mozilla.org/en-US/docs/Web/API/Request
We should do the same too, to allow workers to parse content sent in (even factoring in the caveats of #1). Things to do:
FetchResponse
into a new FetchBody
class, have FetchResponse
inherit from itFetchRequest
also inherit from it, and read in the request body as an InputStream.This is a meta issue that will have to be split into multiple issues at some point, because there's a lot to do here.
The most fundamental and important difference is that the Web APIs are split between Push and Notification APIs. Right now Chrome enforces that you must show a notification in response to a push, but with the Budget API that's going to change.
iOS has a split, sort of, but it's not one that is very useful. You can send a silent notification, which would serve as the equivalent of a web push, but:
The combination of those two factors leads me to think that I'd rather enforce that you have to show a notification in response to a push than mess around with silent notifications (maybe in the future we can make it a customisable thing). But this opens up a new issue: traditionally, the content of an iOS notification is decided on the server, not the client. So we wouldn't be able to mirror the web APIs for customising notification content locally. But...
In iOS 10, Apple introduced Notification Service Extensions. They're small targets, separate from your main app, that are spun up whenever you receive a notification, and before it is displayed. Within a certain time limit, you can customise the contents of this notification before the user ever sees it. So we can spin up the worker, run the push event and listen for a showNotification
call. But two big issues with these extensions:
They run on a very, very tight memory limit. Apple doesn't say what that limit is, and I suspect it's dynamic, or depends on device. However, I ran some encouraging early tests that were able to create a JSContext, and assign an ArrayBuffer of about 8MB before the process was terminated. So we have some space to play with, I'm just not sure how much (once the rest of the worker APIs are added, which they weren't when I did those tests)
They're in a separate process to the main app. It's quite plausible (likely, even) that a worker might call update()
in response to a push, which might result in an entirely new worker being installed. The main app won't be aware of any of that happening. So somehow we need the extension to check if the main app is active in the background, and send updates over as needed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.