On 2015-05-07 7:07 AM, David Rajchenbach-Teller wrote:
From what I gather, ServiceWorkers are now The Right Thing To Do if a
webpage needs some off main thread pre/post processing on server-sent
data. This got me thinking that pre/post processing is exactly what
AdBlock Plus is doing.
So, I wonder: could AdBlock Plus be reimplemented using a slightly
beefed up browser-wide ServiceWorker? Could add-on authors similarly
implement, say, image-blocking for slow-connections using a similar
mechanism? What about anti-viruses, which could possibly perform scans
on e.g. swf before it is executed, using js-ctypes and ServiceWorkers?
These types of add-ons are usually implemented by registering a content
policy implementation which is a service that we call into from the main
thread to determine whether or not to load content. Service workers
however are full fledged workers that are currently installed for a URL
scope under one origin, and they intercept the network fetch and have a
lot of power over what to do with it. They can just log the request,
and let it go to the network, synthesize an error response, send back a
cached response, or generate a dynamic response that may be fully
generated. IOW, they can do a *lot* more than a content policy
implementation.
There are two problems which make what you're suggesting not a great idea:
1. Because service workers run on their own thread, they add some
latency for determining what to do for each network request. Therefore
running them for all network requests across the entire browser is
probably impractical.
2. As they are currently implemented, they can only intercept the
requests that are coming from a specific scope under a specific origin.
Currently it's not possible to register a global service worker for
intercepting all network requests no matter where they are coming from.
Also, they cannot see the insides of a response for a cross-origin
request (which will essentially be all requests for a service worker
similar to what you have in mind) which makes them unsuitable for things
such as anti-virus scanners.
I think that service workers are probably too big of a hammer for
supporting use cases such as adblock, image blocking, etc. They are
probably the right level of abstraction for something like a swf virus
scanner but they're restricted in what they can do with those as I
mentioned above. And I suspect that as a mechanism for intercepting all
network requests, they will be too slow.
It's probably much better to come up with specific APIs for these use
cases where are current solutions are insufficient.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform