feat(apps): puter.apps.get() accepts a URL (#4686)

A string containing :// is looked up as a URL instead of a name. The
puter-apps driver's read takes id.url and resolves it through
appUidFromOrigin, so it returns the same app a page on that origin acts
as.
This commit is contained in:
Daniel Salazar authored and GitHub committed 2026-11-17 21:24:41 -07:00
1 parent 6b7541d0b6
commit 327eef2d32
9 files changed
+199 -8

No files matched your search

+47 -2
View File
@@ -4,7 +4,7 @@ description: Retrieve details of your Puter app.
platforms: [websites, apps, nodejs, workers]
---
Returns an app with the given name.
Returns an app with the given name or URL.
If the app does not exist, the promise will be rejected.
@@ -13,6 +13,8 @@ If the app does not exist, the promise will be rejected.
```js
puter.apps.get(name)
puter.apps.get(name, options)
puter.apps.get(url)
puter.apps.get(url, options)
```
## Parameters
@@ -21,6 +23,10 @@ puter.apps.get(name, options)
The name of the app to get.
#### `url` (required)
A URL on the app's website, such as `https://my-app.puter.site/about`. Puter.js treats any string that contains `://` as a URL. Only the URL's origin is matched, so this returns the same app that a page on that origin acts as when it calls Puter.js. See [Getting an app by URL](#getting-an-app-by-url).
#### `options` (Object) (optional)
An object containing the following properties:
@@ -32,7 +38,22 @@ An object containing the following properties:
## Return value
A `Promise` that will resolve to the [`App`](/Objects/app/) object with the given name.
A `Promise` that will resolve to the [`App`](/Objects/app/) object with the given name or URL.
## Errors
| Code | When |
|------|------|
| `not_found` | No app has this name, or no app runs at this URL's origin. |
| `bad_request` | The URL isn't an `http://`, `https://`, or browser extension URL. |
| `app_blocked` | The URL's origin is blocked from using Puter. |
| `forbidden` | The app is protected and you don't have access to it. |
## Getting an app by URL
A URL matches the app whose index URL is the root of that URL's origin. For example, `https://my-app.puter.site/about?tab=2` returns the app whose index URL is `https://my-app.puter.site/` or `https://my-app.puter.site/index.html`. An app whose index URL is below the root, such as `https://example.com/tools/`, isn't returned for a URL.
A website that isn't registered as an app gets an app the first time a user signs in to Puter from one of its pages, so you can get it by URL after that. The `name` and `title` of that app are both its `uid`.
## Examples
@@ -62,3 +83,27 @@ A `Promise` that will resolve to the [`App`](/Objects/app/) object with the give
</body>
</html>
```
### Get an app by its URL
```html;app-get-by-url
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// (1) Create an app at the root of a random origin
let appName = puter.randName();
await puter.apps.create(appName, `https://${appName}.example.com/`);
// (2) Get it with any URL on that origin
let app = await puter.apps.get(`https://${appName}.example.com/about`);
puter.print(`Found "${app.name}" by URL: id: ${app.uid}<br>`);
// (3) Delete the app (cleanup)
await puter.apps.delete(appName);
})();
</script>
</body>
</html>
```
+1
View File
@@ -8,6 +8,7 @@ New features, changes, and fixes in Puter.js and the Puter APIs, grouped by day,
## November 17, 2026
- Added URL lookups to [`puter.apps.get()`](/Apps/get/). Pass a URL such as `https://my-app.puter.site/about` instead of a name to get the app at that URL's origin. See [Getting an app by URL](/Apps/get/#getting-an-app-by-url).
- Fixed [`puter.ui.contextMenu()`](/UI/contextMenu/) menus with a submenu inside a submenu staying open after an item in the inner submenu was chosen. The inner submenu also closes when the submenu it belongs to closes.
## November 16, 2026
+6
View File
@@ -976,6 +976,12 @@ const examples = [
slug: 'app-get',
source: '/playground/examples/app-get.html',
},
{
title: 'Get an app by its URL',
description: 'Look up the app at a website\'s origin with Puter.js apps API. Run and experiment with this example directly in the playground.',
slug: 'app-get-by-url',
source: '/playground/examples/app-get-by-url.html',
},
],
},
{
@@ -0,0 +1,19 @@
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// (1) Create an app at the root of a random origin
let appName = puter.randName();
await puter.apps.create(appName, `https://${appName}.example.com/`);
// (2) Get it with any URL on that origin
let app = await puter.apps.get(`https://${appName}.example.com/about`);
puter.print(`Found "${app.name}" by URL: id: ${app.uid}<br>`);
// (3) Delete the app (cleanup)
await puter.apps.delete(appName);
})();
</script>
</body>
</html>