// in page.html
navigator.serviceWorker.controller.postMessage({'hello':'world'});
// in sw.js
self.addEventListener('message', event => {
let providerHandler = { | |
get: async(target, name) => { | |
console.log('load someting from remote...') | |
return new Promise( (res, rej) => { | |
setTimeout(() => res(42), 4200) | |
}) | |
}, | |
set: function (obj, prop, value) { | |
return new Promise((res, rej) => { |
/** | |
* Encryption class for encrypt/decrypt that works between programming languages. | |
* | |
* @author Vee Winch. | |
* @link https://stackoverflow.com/questions/41222162/encrypt-in-php-openssl-and-decrypt-in-javascript-cryptojs Reference. | |
* @link https://github.com/brix/crypto-js/releases crypto-js.js can be download from here. | |
*/ | |
class Encryption { |
<!DOCTYPE html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Concept Chat</title> | |
<link rel="stylesheet" href="index.css" > | |
</head> | |
<body> |
// Example below is with mitm6 (https://github.com/fox-it/mitm6/) | |
// Note: Adding the '--add-binary' option here is specific to mitm6, not required in all cases. | |
# pip install pyinstaller | |
# pyinstaller --clean -F --add-binary="/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0:." ./mitm6.py | |
// The step above will create a single binary in the ./dist/ directory called mitm6 | |
// Install staticx and dependencies |
/** | |
* @param {object} scope - Object that all bound data will be attached to. | |
*/ | |
function twoWayBind(scope) { | |
// a list of all bindings used in the DOM | |
// @example | |
// { 'person.name': [<input type="text" data-bind="person.name"/>] } | |
var bindings = {}; | |
// each bindings old value to be compared for changes |
<!-- | |
This demo shows two ways to detect changes to a DOM node `.textContent`, one | |
using a `MutationObserver` and the other using an ES2015 `Proxy`. | |
From testing, a `Proxy` appears to be 6-8x faster than using a MO in Chrome 50. | |
**Update**: removing the `Proxy` altogether speeds up the MO to be inline with the Proxy. | |
This has something to do with how the browser queues/prioritizes Proxies over MO. |
/** | |
@class BroadcastChannel | |
A simple BroadcastChannel polyfill that works with all major browsers. | |
Please refer to the official MDN documentation of the Broadcast Channel API. | |
@see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API">Broadcast Channel API on MDN</a> | |
@author Alessandro Piana | |
@version 0.0.6 | |
*/ | |
/* |
/* Sometimes it's pretty easy to run ito troubles with React ES6 components. | |
Consider the following code: */ | |
class EventStub extends Component { | |
componentDidMount() { | |
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind | |
} | |
componentWillUnmount() { | |
window.removeEventListener('resize', this.onResize.bind(this)); |
This is a working example on how to store CryptoKey
s locally in your browser. We are able to save the objects, without serializing them. This means we can keep them not exportable (which might be more secure?? not sure what attack vectors this prevents).
To try out this example, first make sure you are in a browser that has support for async...await
and indexedDB (latest chrome canary with chrome://flags
"Enable Experimental Javascript" works). Load some page and copy and paste this code into the console. Then call encryptDataSaveKey()
. This will create a private/public key pair and encrypted some random data with the private key. Then save both of them. Now reload the page, copy in the code, and run loadKeyDecryptData()
. It will load the keys and encrypted data and decrypt it. You should see the same data logged both times.