Skip to content

Commit

Permalink
Fix URL handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Jun 12, 2022
1 parent 3130340 commit 64a08e0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/worker/src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt;
use std::marker::PhantomData;
use std::rc::{Rc, Weak};

use gloo_utils::window;
use js_sys::Array;
use web_sys::{Blob, BlobPropertyBag, Url};

Expand All @@ -15,9 +16,23 @@ use crate::traits::Worker;
use crate::{Callback, Shared};

fn create_worker(path: &str) -> DedicatedWorker {
let wasm_url = path.replace(".js", "_bg.wasm");
let js_shim_url = Url::new_with_base(
path,
&window().location().href().expect("failed to read href."),
)
.expect("failed to create url for javascript entrypoint")
.to_string();

let wasm_url = js_shim_url.replace(".js", "_bg.wasm");

let array = Array::new();
array.push(&format!(r#"importScripts("{}");wasm_bindgen("{}");"#, path, wasm_url).into());
array.push(
&format!(
r#"importScripts("{}");wasm_bindgen("{}");"#,
js_shim_url, wasm_url
)
.into(),
);
let blob = Blob::new_with_str_sequence_and_options(
&array,
BlobPropertyBag::new().type_("application/javascript"),
Expand Down

0 comments on commit 64a08e0

Please sign in to comment.