Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions sdk/tests/js/webgl-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3183,13 +3183,16 @@ var getBaseDomain = function(host) {
}

var runningOnLocalhost = function() {
return window.location.hostname.indexOf("localhost") != -1 ||
window.location.hostname.indexOf("127.0.0.1") != -1;
let hostname = window.location.hostname;
return hostname == "localhost" ||
hostname == "127.0.0.1" ||
hostname == "::1";
}

var getLocalCrossOrigin = function() {
var domain;
if (window.location.host.indexOf("localhost") != -1) {
// TODO(kbr): figure out whether to use an IPv6 loopback address.
domain = "127.0.0.1";
} else {
domain = "localhost";
Expand Down Expand Up @@ -3222,20 +3225,20 @@ var getRelativePath = function(path) {
}

async function loadCrossOriginImage(img, webUrl, localUrl) {
img.src = getUrlOptions().imgUrl || webUrl;
try {
console.log('[loadCrossOriginImage]', 'trying', img.src);
await img.decode();
return;
} catch {}

if (runningOnLocalhost()) {
img.src = getLocalCrossOrigin() + getRelativePath(localUrl);
console.log('[loadCrossOriginImage]', ' trying', img.src);
await img.decode();
return;
}

try {
img.src = getUrlOptions().imgUrl || webUrl;
console.log('[loadCrossOriginImage]', 'trying', img.src);
await img.decode();
return;
} catch {}

throw 'createCrossOriginImage failed';
}

Expand Down