skottie - Keep track of script origin for cross-site loading.

Bug: skia:
Change-Id: Iaadc705f92aa52b8ade118ee6dc846b3e55191ff
Reviewed-on: https://skia-review.googlesource.com/c/181882
Auto-Submit: Joe Gregorio <jcgregorio@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/skottie/modules/skottie-player-sk/skottie-player-sk.js b/skottie/modules/skottie-player-sk/skottie-player-sk.js
index 42bbfd8..6b345a0 100644
--- a/skottie/modules/skottie-player-sk/skottie-player-sk.js
+++ b/skottie/modules/skottie-player-sk/skottie-player-sk.js
@@ -97,8 +97,15 @@
   ${settingsTemplate(ele)}
 </div>`;
 
+// This element might be loaded from a different site, and that means we need
+// to be careful about how we construct the URL back to the canvas.wasm file.
+// Start by recording the script origin.
+const scriptOrigin = new URL(document.currentScript.src).origin;
+
 const canvasReady = CanvasKitInit({
-  locateFile: (file) => '/static/'+file,
+  locateFile: (file) => {
+    return `${scriptOrigin}/static/${file}`;
+  },
 }).ready();
 
 window.customElements.define('skottie-player-sk', class extends HTMLElement {