-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This can be used to load and serve replay service worker. Initially, this is compatible with wabac.js but in future we could support other replay service worker implementations such as reconstructive.js too.
- Loading branch information
Showing
6 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
async function init() { | ||
const path = window.location.pathname; | ||
const segments = path.split("/"); | ||
const collection = segments[1]; | ||
const url = path.substring(segments[1].length + segments[2].length + 3); | ||
|
||
const collAdded = new Promise((resolve) => { | ||
navigator.serviceWorker.addEventListener('message', (event) => { | ||
if (event.data.msg_type === 'collAdded') { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
|
||
await navigator.serviceWorker.register("/sw.js"); | ||
|
||
if (navigator.serviceWorker.controller || (await navigator.serviceWorker.ready).active) { | ||
navigator.serviceWorker.controller.postMessage({ | ||
msg_type: 'addColl', | ||
name: collection, | ||
type: 'live', | ||
file: {'sourceUrl': 'proxy:'}, | ||
extraConfig: { | ||
baseUrl: window.location.href, | ||
isLive: false, | ||
archivePrefix: '/' + segments[1] + '/', | ||
} | ||
}); | ||
} | ||
|
||
window.addEventListener('message', event => { | ||
let data = event.data; | ||
if (data.wb_type === 'title') { | ||
document.title = data.title; | ||
} else if (data.wb_type === 'replace-url') { | ||
history.replaceState({}, data.title, '/' + collection + '/' + data.ts + '/' + data.url) | ||
} | ||
}); | ||
|
||
await collAdded; | ||
|
||
const style = document.createElement("style"); | ||
style.innerHTML = 'html, body, iframe { margin:0; padding:0; width: 100%; height: 100% }'; | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = '/w/' + segments[1] + '/' + segments[2] + 'mp_/' + url; | ||
document.body.append(style, iframe); | ||
} | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters