oduwsdl / ipwb

InterPlanetary Wayback: A distributed and persistent archive replay system using IPFS
MIT License
616 stars 39 forks source link

Account for mementos' Service Worker in Service Worker replay override #386

Open machawk1 opened 6 years ago

machawk1 commented 6 years ago

Given we use ServiceWorkers for rewriting, if the JavaScript of a memento uses ServiceWorkers, will the ipwb replay SW still function as expected?

ibnesayeed commented 6 years ago

So far, SW is generally being used for enhancement of the experience and not essential for the page to function. However, we need to mask any SW registration in the page for now for the replay to avoid any unwanted behavior.

machawk1 commented 6 years ago

@ibnesayeed But it could be used for essential functionality, correct? It likely is not now due to its newness, support, accessibility, etc.

It would be interesting to set up some tests for the ipwb SW to evaluate how it behaves with different levels of essentiality mementos' respective SWs.

Perhaps a first step would be to check for the existence of SW code in the memento. This is reminiscent of @N0taN3rd's CNN investigation: http://ws-dl.blogspot.com/2017/01/2017-01-20-cnncom-has-been-unarchivable.html

ibnesayeed commented 6 years ago

Yes! (to all your points)

machawk1 commented 6 years ago

I have added three files in c0507881cac51fd9a73b58fda457ff62d9200d49 (issue-386 branch, in tests/serviceWorkers-386/) that fundamentally use a service worker when invoked through a user interaction. To use the files:

  1. Start a server instance e.g., using php -S localhost:8081
  2. Access http://localhost:8081/sw.html
  3. Register the serviceWorker using the button.
  4. Send an action to the serviceWorker using the other button.

The DOM should change with the contents of the message returned from the SW after sending it a message.

The next step will be to create a WARC of these three resources then determine how the ipwb serviceWorker interacts/affects the memento's SW. Note that SWs typically requires HTTPS if not on localhost.

A caveat that's bitten me a few times: Chrome is aggressive with caching SWs. Even when told to clear them using devtools, old SW code is used. Incognito helps so long as there are no other incognito windows open, else the same scenario of cached SWs results.