Skip to content

Peergos/iframe-sw-streams

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

sw + streams + iframe

This demonstrates a bug in safari when trying to use a service worker with writable streams in a nested iframe. The example works in all other browsers.

To try it out visit https://safaribug.peergos.com/ or run it on localhost.

Run (requires java >= 11)

java Server.java

Navigate to: localhost:8000

What is this all about?

service worker + writable streams is a useful mechanism to load generated/decrypted content in response to a request

This is demonstrated on index.html whereby the request to play/seek the video is intercepted via a service worker and data retrieved in main.js.

A writable stream is setup between main.js and sw.js and pipes the data back to the service worker.

Sandboxed iframe

To take this one step further, In chrome and firefox (but not safari) it is possible to load content into an iframe inside an iframe via a similar mechanism.

The purpose is to have the inner iframe on a subdomain subdomain.domain.com to provide a secure sandbox to load arbitrary html.

The file Server.java provides a minimal web server that sets additional response headers (ie COOP, COEP, CORP) and is directly executable without compilation.

Structure

main.js constructs an iframe and adds it to index.html.

The .src is set to /apps/sandbox/sandbox.html which contains the inner iframe.

The associated file sandbox.js loads a service worker to intercept requests.

And like the video streaming example, the data is ultimately loaded from main.js.

Safari issues

  1. subdomain.localhost:8000 is not supported (webkit bug from 2016, workaround - deploy to a remote host)
  2. the iframe inside an iframe does not work. nothing in console to indicate what the problem is.

Note: due to the minimal nature of this example - you will need to clear the cache/hard reset each time loading index.html

Alternative method (doesn't require the hard reset - but is the full app and therefore much more code):

  1. Create an account on peergos-demo.net
  2. upload a minimal .html file
  3. view the html file in the in-built html viewer (view action available from right-click menu)

The file will be viewable in chrome and firefox, but not safari.

Please make sure that you are not in incognito mode.

About

Demonstrate Safari bug affecting custom apps in Peergos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 70.7%
  • Java 25.2%
  • HTML 3.8%
  • CSS 0.3%