Skip to content

Instantly share code, notes, and snippets.

@bkardell
Last active December 22, 2015 23:19
Show Gist options
  • Select an option

  • Save bkardell/6545573 to your computer and use it in GitHub Desktop.

Select an option

Save bkardell/6545573 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="../oasis/javascript/oasis.js.html"></script>
</head>
<body>
<textarea rows="40" cols="80" id="results"></textarea>
<script>
(function(){
var contents = {
// project/lib
"jquery": ["1.7","1.7.1","1.7.2","1.8.0","1.8.1","1.8.2","1.8.3","1.8.3","1.9.0","1.9.1","1.10.0","1.10.1","1.10.2","2.0.0","2.0.1","2.0.2","2.0.3"],
"foo": ["1.0.0"]
};
var searchSemver = function (data, search) {
var re = new RegExp(search.replace(".","\."));
return data.reduce(function(prev,cur){ return (re.test(cur) && cur > prev) ? cur : prev; });
}
function tryFetching(url) {
try {
var el = document.getElementById("results");
var client = new XMLHttpRequest();
var handler = function () {
if (this.readyState === this.DONE) {
if (this.status === 200) {
el.value += "got..." + url + "::" + this.response + "\n";
} else {
el.value += "something went horribly wrong..." + url + "::" + this.response + "\n";
}
}
};
client.open("GET", url + "?s=" + Date.now());
client.onreadystatechange = handler;
client.responseType = "text";
client.setRequestHeader("Accept", "text");
client.send();
} catch (e) {
el.value += "something went horribly wrong..." + url + "::" + this.response + "\n";
}
};
// On startup just illustrate that I can fetch these...
tryFetching("file1.js");
tryFetching("file2.js");
tryFetching("jquery.min.js"); //note this one succeeds
console.log("Getting setup....");
Oasis.connect('tap').then(function (port) {
console.log("sending!" + contents);
port.send("init", contents);
port.onRequest("get", function (spec) {
// same as above fails - seen as parent origin
tryFetching("jquery.min.js");
// works. wtf.
tryFetching(" http://127.0.0.1/~bkardell/iframes/jquery.min.js");
});
});
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment