Skip to content

Commit 35eca6e

Browse files
committedSep 23, 2024
Add version to navigator.userAgent
A la Deno and Bun.
1 parent d3c3403 commit 35eca6e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed
 

‎qjs.c

+5
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
164164
JSValue global = JS_GetGlobalObject(ctx);
165165
JS_SetPropertyFunctionList(ctx, global, global_obj, countof(global_obj));
166166
JS_SetPropertyFunctionList(ctx, global, &argv0, 1);
167+
JSValue navigator = JS_NewObject(ctx);
168+
char version[32];
169+
snprintf(version, sizeof(version), "quickjs-ng/%s", JS_GetVersion());
170+
JS_DefinePropertyValueStr(ctx, navigator, "userAgent", JS_NewString(ctx, version), JS_PROP_ENUMERABLE);
171+
JS_DefinePropertyValueStr(ctx, global, "navigator", navigator, JS_PROP_C_W_E);
167172
JS_FreeValue(ctx, global);
168173

169174
return ctx;

0 commit comments

Comments
 (0)