var code = 'postMessage(123);'; var blob = new Blob([code],{type: "text/javascript"}); var ref = URL.createObjectURL(blob); var worker = new Worker(ref); ..... URL.revokeObjectURL(ref);