summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorrandomicon00 <20146907+randomicon00@users.noreply.github.com>2022-05-14 11:00:02 +0100
committerGitHub <noreply@github.com>2022-05-14 12:00:02 +0200
commitf82a79ffdbc6b8f2fc4bbe6174ad33cb22e64386 (patch)
treeb8a6021de1157fe0cb70036a9eef79a4a2d0cac1 /runtime
parent20ee3110d84c72f4a28cc5c9083b5dda47181602 (diff)
feat: add userAgent property to Navigator's prototype (#14415)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/examples/hello_runtime.rs2
-rw-r--r--runtime/js/99_main.js12
-rw-r--r--runtime/web_worker.rs5
-rw-r--r--runtime/worker.rs7
-rw-r--r--runtime/worker_bootstrap.rs2
5 files changed, 19 insertions, 9 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs
index a6b7fb06b..07e42f0ff 100644
--- a/runtime/examples/hello_runtime.rs
+++ b/runtime/examples/hello_runtime.rs
@@ -38,11 +38,11 @@ async fn main() -> Result<(), AnyError> {
runtime_version: "x".to_string(),
ts_version: "x".to_string(),
unstable: false,
+ user_agent: "hello_runtime".to_string(),
},
extensions: vec![],
unsafely_ignore_certificate_errors: None,
root_cert_store: None,
- user_agent: "hello_runtime".to_string(),
seed: None,
source_map_getter: None,
format_js_error_fn: None,
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index d83a2e6c8..cf2525b06 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -301,7 +301,7 @@ delete Object.prototype.__proto__;
const navigator = webidl.createBranded(Navigator);
- let numCpus;
+ let numCpus, userAgent;
ObjectDefineProperties(Navigator.prototype, {
gpu: {
@@ -320,6 +320,14 @@ delete Object.prototype.__proto__;
return numCpus;
},
},
+ userAgent: {
+ configurable: true,
+ enumerable: true,
+ get() {
+ webidl.assertBranded(this, NavigatorPrototype);
+ return userAgent;
+ },
+ },
});
const NavigatorPrototype = Navigator.prototype;
@@ -575,6 +583,7 @@ delete Object.prototype.__proto__;
ppid,
unstableFlag,
cpuCount,
+ userAgent: userAgentInfo,
} = runtimeOptions;
colors.setNoColor(noColor || !isTty);
@@ -582,6 +591,7 @@ delete Object.prototype.__proto__;
location.setLocationHref(locationHref);
}
numCpus = cpuCount;
+ userAgent = userAgentInfo;
registerErrors();
const internalSymbol = Symbol("Deno.internal");
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 23281ad68..9582d0f7f 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -323,7 +323,6 @@ pub struct WebWorkerOptions {
pub extensions: Vec<Extension>,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store: Option<RootCertStore>,
- pub user_agent: String,
pub seed: Option<u64>,
pub module_loader: Rc<dyn ModuleLoader>,
pub create_web_worker_cb: Arc<ops::worker_host::CreateWebWorkerCb>,
@@ -386,7 +385,7 @@ impl WebWorker {
Some(main_module.clone()),
),
deno_fetch::init::<Permissions>(deno_fetch::Options {
- user_agent: options.user_agent.clone(),
+ user_agent: options.bootstrap.user_agent.clone(),
root_cert_store: options.root_cert_store.clone(),
unsafely_ignore_certificate_errors: options
.unsafely_ignore_certificate_errors
@@ -395,7 +394,7 @@ impl WebWorker {
..Default::default()
}),
deno_websocket::init::<Permissions>(
- options.user_agent.clone(),
+ options.bootstrap.user_agent.clone(),
options.root_cert_store.clone(),
options.unsafely_ignore_certificate_errors.clone(),
),
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 7165b04f0..4c38d232f 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -52,7 +52,6 @@ pub struct WorkerOptions {
pub extensions: Vec<Extension>,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store: Option<RootCertStore>,
- pub user_agent: String,
pub seed: Option<u64>,
pub module_loader: Rc<dyn ModuleLoader>,
// Callbacks invoked when creating new instance of WebWorker
@@ -111,7 +110,7 @@ impl MainWorker {
options.bootstrap.location.clone(),
),
deno_fetch::init::<Permissions>(deno_fetch::Options {
- user_agent: options.user_agent.clone(),
+ user_agent: options.bootstrap.user_agent.clone(),
root_cert_store: options.root_cert_store.clone(),
unsafely_ignore_certificate_errors: options
.unsafely_ignore_certificate_errors
@@ -120,7 +119,7 @@ impl MainWorker {
..Default::default()
}),
deno_websocket::init::<Permissions>(
- options.user_agent.clone(),
+ options.bootstrap.user_agent.clone(),
options.root_cert_store.clone(),
options.unsafely_ignore_certificate_errors.clone(),
),
@@ -376,9 +375,9 @@ mod tests {
runtime_version: "x".to_string(),
ts_version: "x".to_string(),
unstable: false,
+ user_agent: "x".to_string(),
},
extensions: vec![],
- user_agent: "x".to_string(),
unsafely_ignore_certificate_errors: None,
root_cert_store: None,
seed: None,
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs
index f1ffd1b3d..68f223be5 100644
--- a/runtime/worker_bootstrap.rs
+++ b/runtime/worker_bootstrap.rs
@@ -20,6 +20,7 @@ pub struct BootstrapOptions {
/// Sets `Deno.version.typescript` in JS runtime.
pub ts_version: String,
pub unstable: bool,
+ pub user_agent: String,
}
impl BootstrapOptions {
@@ -42,6 +43,7 @@ impl BootstrapOptions {
"ppid": ppid(),
"target": env!("TARGET"),
"v8Version": deno_core::v8_version(),
+ "userAgent": self.user_agent,
});
serde_json::to_string_pretty(&payload).unwrap()
}