aostiles
aostiles
DDeno
Created by aostiles on 8/1/2024 in #help
Enabling Web APIs embedded
Hi, I'm trying to use the TextEncoder web api in an embedded scenario. Here's what I'm doing:
struct NoopTimersPermission;
impl deno_web::TimersPermission for NoopTimersPermission {
fn allow_hrtime(&mut self) -> bool {
false
}
}

let blob_store = Arc::new(deno_web::BlobStore::default());
let extensions: Vec<Extension> = vec![
deno_url::init_ops_and_esm(),
deno_webidl::deno_webidl::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(),
deno_web::deno_web::init_ops_and_esm::<NoopTimersPermission>(blob_store, None)
];

let options = RuntimeOptions {
module_loader: Some(loader),
extensions,
..Default::default()
};

let mut runtime = JsRuntime::new(options);

// Run the event loop to completion
runtime.run_event_loop(PollEventLoopOptions::default()).await
.map_err(|e| format!("Failed to run event loop: {}", e))?;
struct NoopTimersPermission;
impl deno_web::TimersPermission for NoopTimersPermission {
fn allow_hrtime(&mut self) -> bool {
false
}
}

let blob_store = Arc::new(deno_web::BlobStore::default());
let extensions: Vec<Extension> = vec![
deno_url::init_ops_and_esm(),
deno_webidl::deno_webidl::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(),
deno_web::deno_web::init_ops_and_esm::<NoopTimersPermission>(blob_store, None)
];

let options = RuntimeOptions {
module_loader: Some(loader),
extensions,
..Default::default()
};

let mut runtime = JsRuntime::new(options);

// Run the event loop to completion
runtime.run_event_loop(PollEventLoopOptions::default()).await
.map_err(|e| format!("Failed to run event loop: {}", e))?;
but I can't seem to reference TextEncoder at runtime in my JS code. Is there something I'm doing wrong? Thanks.
4 replies