Last active
August 22, 2017 09:34
-
-
Save tobbez/246861480da9dda07f3a to your computer and use it in GitHub Desktop.
Proof of concept for migrating localStorage from HTTP to HTTPS #2
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>SSL localStorage migration proof of concept #2</title> | |
<script type="text/javascript"> | |
window.addEventListener('message', function (ev) { | |
var origin = ev.origin || event.originalEvent.origin; | |
if (origin !== 'http://' + document.location.host && origin != 'https://' + document.location.host) { | |
return; | |
} | |
var message = ev.data; | |
if (message.type === 'migrate-finished') { | |
localStorage.removeItem('LocalStorage.pb'); | |
document.location = 'https://' + document.location.toString().substr(4); | |
} | |
}); | |
if (document.location.protocol === 'http:') { | |
if (localStorage.getItem('LocalStorage.pb') !== null) { | |
document.addEventListener('DOMContentLoaded', function () { | |
var iframe = document.createElement('iframe'); | |
iframe.src = 'https://' + document.location.host + document.location.pathname.substr(0, document.location.pathname.lastIndexOf('/') + 1) + 'migrate.html'; | |
iframe.setAttribute('style', 'display: none'); | |
iframe.addEventListener('load', function () { | |
iframe.contentWindow.postMessage({'type': 'localstorage-data', data: localStorage.getItem('LocalStorage.pb')}, 'https://' + document.location.host); | |
}); | |
document.body.appendChild(iframe); | |
}); | |
} else { | |
document.location = 'https://' + document.location.toString().substr(4); | |
} | |
} else { | |
// Load game client | |
alert('Load client'); | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>SSL localStorage migration proof of concept</title> | |
<script type="text/javascript"> | |
window.addEventListener('message', function (ev) { | |
var origin = ev.origin || event.originalEvent.origin; | |
if (origin !== 'http://' + document.location.host && origin != 'https://' + document.location.host) { | |
return; | |
} | |
var message = ev.data; | |
if (message.type === 'localstorage-data') { | |
localStorage.setItem('LocalStorage.pb', message.data); | |
document.location = 'http://' + document.location.host + document.location.pathname.substr(0, document.location.pathname.lastIndexOf('/') + 1) + 'migrate_finished.html'; | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>SSL localStorage migration proof of concept</title> | |
<script type="text/javascript"> | |
window.parent.postMessage({'type': 'migrate-finished'}, 'http://' + document.location.host); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment