Skip to content

Commit

Permalink
feat(js-runtime,docs): add navigator.userAgent API (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz committed Dec 18, 2022
1 parent 18aaee0 commit f538576
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
16 changes: 13 additions & 3 deletions .changeset/config.json
@@ -1,10 +1,20 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.0.1/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "lagonapp/lagon" }],
"changelog": [
"@changesets/changelog-github",
{
"repo": "lagonapp/lagon"
}
],
"commit": false,
"fixed": [],
"fixed": [
[
"@lagon/runtime",
"@lagon/js-runtime"
]
],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch"
}
}
6 changes: 6 additions & 0 deletions .changeset/tricky-dogs-impress.md
@@ -0,0 +1,6 @@
---
'@lagon/docs': minor
'@lagon/js-runtime': minor
---

Add `navigator.userAgent` API
8 changes: 7 additions & 1 deletion packages/docs/pages/runtime-apis.mdx
Expand Up @@ -32,7 +32,7 @@ You can log multiple objects, and use string substitution. [See the documentatio

### `process`

The only usage of `process` is to get [environment variables](/cloud/environment-variables) via `process.env`.
The only usage of `process` is to access [environment variables](/cloud/environment-variables) via `process.env`.

Example:

Expand All @@ -44,6 +44,12 @@ export function handler(request: Request): Response {

---

### `navigator.userAgent`

`navigator.userAgent` is a fixed string that can be used to detect the current runtime. Its value is always `Lagon/VERSION`, where `VERSION` is the current version of the Lagon Runtime.

---

### `crypto`

The standard `crypto` object.
Expand Down
4 changes: 2 additions & 2 deletions packages/js-runtime/package.json
@@ -1,6 +1,6 @@
{
"name": "@lagon/js-runtime",
"version": "0.1.8",
"version": "0.1.10",
"description": "JavaScript Runtime",
"private": true,
"type": "module",
Expand All @@ -17,4 +17,4 @@
"blob-polyfill": "^7.0.20220408",
"web-streams-polyfill": "^3.2.1"
}
}
}
1 change: 1 addition & 0 deletions packages/js-runtime/src/index.ts
Expand Up @@ -9,6 +9,7 @@ import './runtime/blob';
import './runtime/global/console';
import './runtime/global/process';
import './runtime/global/crypto';
import './runtime/global/navigator';
import './runtime/http/URLSearchParams';
import './runtime/http/URL';
import './runtime/http/Headers';
Expand Down
12 changes: 12 additions & 0 deletions packages/js-runtime/src/runtime/global/navigator.ts
@@ -0,0 +1,12 @@
// esbuild will inline the version as a const, and since both
// runtime and js-runtime are versioned together, we can safely
// import the version from the package.json instead of injecting
// it from the Rust code.
import { version } from '../../../package.json';

(globalThis => {
globalThis.navigator = {
...globalThis.navigator,
userAgent: `Lagon/${version}`,
};
})(globalThis);

1 comment on commit f538576

@vercel
Copy link

@vercel vercel bot commented on f538576 Dec 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./packages/docs

docs-git-main-lagon.vercel.app
lagon-docs.vercel.app
docs-lagon.vercel.app
docs.lagon.app

Please sign in to comment.