fix(web): open artifacts outside the installed app context
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# Artifact browser hand-off
|
||||
|
||||
Artifact URLs are within the PWA's root scope. Android can therefore capture
|
||||
same-origin `_blank` links back into the installed app, even though the source
|
||||
requested a new window. The artifact document has no app navigation shell, so
|
||||
Back can close that activity instead of returning to the run.
|
||||
|
||||
Every artifact type now opens in the browser by default; optional in-app media
|
||||
and Markdown previews have an explicitly named secondary action. The shared web
|
||||
navigation helper requests a browser-specific Android VIEW intent
|
||||
only in an Android installed/fullscreen app. Chrome, Edge, Samsung Internet,
|
||||
Opera and Firefox families have fixed browser package identifiers; unknown
|
||||
Chromium-family hosts use Chrome with the original HTTP(S) URL as browser fallback.
|
||||
The app's own URL/history are not replaced. Normal browser/iOS links retain
|
||||
native `_blank` navigation. Copy and Share never receive an intent URI.
|
||||
|
||||
Only validated HTTP(S) URLs without credentials are accepted. Intent fields are
|
||||
fixed or encoded; original document fragments remain data before the final
|
||||
`#Intent` marker, so they cannot inject actions/packages. Existing artifact CSP,
|
||||
authentication, sandboxing and no-store headers are unchanged. No new artifact
|
||||
origin, public endpoint, credential in a URL or relaxed permission is introduced.
|
||||
|
||||
Sources: [Chrome Android Intents](https://developer.chrome.com/docs/android/intents),
|
||||
[Android PWA capture issue](https://issues.chromium.org/issues/364623620).
|
||||
Chrome requires a user gesture and sanitizes component/selector overrides, so
|
||||
the helper runs synchronously from native actions and never uses a timer.
|
||||
|
||||
Regression evidence: real desktop new-tab creation with original app URL/history
|
||||
preserved; inspected installed-Android intent actions from all main artifact
|
||||
surfaces; ordinary copy URLs; mobile footer bounds at 390/420px. Actual Android
|
||||
intent dispatch/default-browser/channel availability and hardware Back remain a
|
||||
phone verification, not something these desktop captures prove.
|
||||
@@ -8,6 +8,30 @@ test, or a code change without a capture, is `partial` at best.
|
||||
|
||||
Status legend: `todo` · `partial` (some of it works) · `done` (working + captured).
|
||||
|
||||
### Artifact browser hand-off (2026-10-20)
|
||||
|
||||
Artifact opens now use one validated navigation helper across gallery/list,
|
||||
verdict, audit/session/repair, search, viewer and chat links. Android standalone
|
||||
apps request an explicit browser-family VIEW intent: an implicit HTTPS intent or
|
||||
`_blank` alone can be captured by the current WebAPK. Browser packages are fixed
|
||||
by the known browser family, never supplied by artifact/model text; other
|
||||
environments retain native `_blank` links with external/noopener/noreferrer.
|
||||
Copy/Share keep ordinary HTTP(S) URLs. No code replaces the app's own location.
|
||||
Markdown root-relative artifact links are clickable; executable/local URLs remain
|
||||
unlinked. The viewer has an explicit **Open in browser** link and wrapping mobile
|
||||
actions. All file types open in the browser by default; **Preview in app** is an
|
||||
explicit secondary gallery/list action for media and Markdown/text. On touch
|
||||
screens these actions are visible, separate from Open, and at least 44px.
|
||||
|
||||
`test/artifact-browser-probe.mjs` verifies an actual new browser target while the
|
||||
app URL/history remain unchanged, then inspects Android standalone hand-offs for
|
||||
tiles (HTML/Markdown/image), list, search, chat, session and viewer controls. Copy retains HTTP, unsafe links stay
|
||||
inert, and actions fit at 390/420px. Captures are in the approved OpenCode temporary
|
||||
`artifact-browser-captures/` directory. **Android's actual OS/browser launch and
|
||||
Back behavior require the user's phone check**; the desktop test does not claim
|
||||
to reproduce an installed Android WebAPK. Shell cache version is bumped so the
|
||||
new navigation modules refresh on the next app reload.
|
||||
|
||||
### List miniature follow-up (2026-10-20)
|
||||
|
||||
Workflow and run miniatures now share the existing graph layout, right-aligned
|
||||
|
||||
+17
-6
@@ -43,7 +43,8 @@ textarea {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
button,
|
||||
.browser-button {
|
||||
min-height: var(--density-control-height);
|
||||
padding: 0 var(--space-control-pad-inline);
|
||||
border-radius: var(--radius-control);
|
||||
@@ -54,8 +55,9 @@ button {
|
||||
transition: background var(--motion-fast) var(--ease-standard),
|
||||
border-color var(--motion-fast) var(--ease-standard);
|
||||
}
|
||||
button:hover { background: var(--color-elevated); }
|
||||
button:active { background: var(--color-elevated-2); }
|
||||
button:hover, .browser-button:hover { background: var(--color-elevated); }
|
||||
button:active, .browser-button:active { background: var(--color-elevated-2); }
|
||||
.browser-button { display: inline-flex; align-items: center; justify-content: center; font: inherit; text-decoration: none; }
|
||||
button.ghost { background: transparent; border-color: transparent; color: var(--color-muted); }
|
||||
button.ghost:hover { background: var(--tint-hover); color: var(--color-text); }
|
||||
button:disabled { opacity: var(--opacity-disabled); cursor: not-allowed; }
|
||||
@@ -84,7 +86,7 @@ a { color: var(--color-accent); }
|
||||
button, [role="tab"] { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
|
||||
|
||||
@media (any-pointer: coarse) {
|
||||
button, input, select { min-height: 48px; }
|
||||
button, input, select, .browser-button { min-height: 48px; }
|
||||
button { -webkit-tap-highlight-color: transparent; }
|
||||
button:active { background-color: var(--color-elevated-2); }
|
||||
}
|
||||
@@ -243,7 +245,7 @@ button, [role="tab"] { -webkit-user-select: none; user-select: none; touch-actio
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 7px 78px 7px 8px;
|
||||
padding: 7px 100px 7px 8px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
@@ -288,7 +290,16 @@ button, [role="tab"] { -webkit-user-select: none; user-select: none; touch-actio
|
||||
.viewer-placeholder .artifact-play { font-size: 40px; }
|
||||
.viewer-nav { display: flex; gap: var(--space-xs); justify-content: center; }
|
||||
.viewer-page:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
.viewer-actions { display: flex; gap: var(--space-xs); justify-content: flex-end; }
|
||||
.viewer-actions { display: flex; flex-wrap: wrap; min-width: 0; gap: var(--space-xs); justify-content: flex-end; }
|
||||
.viewer-action { white-space: nowrap; }
|
||||
|
||||
@media (any-pointer: coarse) {
|
||||
.artifact-tile-wrap { flex-direction: column; }
|
||||
.artifact-actions { position: static; align-self: stretch; justify-content: flex-end; flex-wrap: wrap; padding: 4px 4px 6px; opacity: 1; pointer-events: auto; }
|
||||
.artifact-action { width: 44px; min-height: 44px; }
|
||||
.artifact-list-row .artifact-actions { transform: none; }
|
||||
.artifact-list-open { padding-right: 8px; }
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-block;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// Artifacts are documents, not app destinations. Android can capture even
|
||||
// _blank links inside an installed PWA's scope; use an explicit VIEW hand-off
|
||||
// there, retaining ordinary URLs for copy/share and every other environment.
|
||||
|
||||
export function artifactBrowserLinkProps(value, environment = globalThis) {
|
||||
if (typeof value !== "string" || value.trim() === "") return null;
|
||||
let url;
|
||||
try {
|
||||
url = new URL(String(value ?? ""), environment.location?.href);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) return null;
|
||||
const standalone = environment.navigator?.standalone === true ||
|
||||
environment.matchMedia?.("(display-mode: standalone)")?.matches === true ||
|
||||
environment.matchMedia?.("(display-mode: fullscreen)")?.matches === true;
|
||||
const userAgent = environment.navigator?.userAgent ?? "";
|
||||
const android = /Android/i.test(userAgent);
|
||||
// An implicit HTTPS VIEW intent can resolve straight back to this WebAPK.
|
||||
// Pin the browser family, never the installed app's link-capturing package.
|
||||
const browserPackage = /EdgA\//i.test(userAgent) ? "com.microsoft.emmx"
|
||||
: /SamsungBrowser\//i.test(userAgent) ? "com.sec.android.app.sbrowser"
|
||||
: /OPR\//i.test(userAgent) ? "com.opera.browser"
|
||||
: /Firefox\//i.test(userAgent) ? "org.mozilla.firefox"
|
||||
: "com.android.chrome";
|
||||
// Intent.parseUri uses the LAST #Intent marker, so an original document
|
||||
// fragment remains data. Every field after our marker is fixed or encoded;
|
||||
// untrusted artifact names/fragments cannot inject intent extras or packages.
|
||||
const href = android && standalone
|
||||
? `intent:${url.href.slice(url.protocol.length)}#Intent;scheme=${url.protocol.slice(0, -1)};action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=${browserPackage};S.browser_fallback_url=${encodeURIComponent(url.href)};end`
|
||||
: url.href;
|
||||
return { href, target: "_blank", rel: "external noopener noreferrer", referrerpolicy: "no-referrer" };
|
||||
}
|
||||
|
||||
/** Recognize same-origin artifacts, including root-relative Markdown links;
|
||||
* never turn arbitrary SPA paths or javascript/data URLs into navigation. */
|
||||
export function isLocalArtifactLink(value, base) {
|
||||
if (!String(value ?? "").startsWith("/artifacts/") && !/^https?:\/\//i.test(String(value ?? ""))) return false;
|
||||
try {
|
||||
const url = new URL(value, base);
|
||||
return url.origin === new URL(base).origin && url.pathname.startsWith("/artifacts/");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
// node with these functions; server-derived text is always assigned through
|
||||
// textContent, never innerHTML.
|
||||
|
||||
import { artifactBrowserLinkProps } from "./artifactNavigation.js";
|
||||
export { artifactBrowserLinkProps } from "./artifactNavigation.js";
|
||||
|
||||
export function h(tag, props = {}, ...children) {
|
||||
const node = document.createElement(tag);
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
@@ -19,6 +22,18 @@ export function h(tag, props = {}, ...children) {
|
||||
return node;
|
||||
}
|
||||
|
||||
/** Run synchronously inside a click/keyboard gesture: Android rejects intents
|
||||
* launched from timers. Never fall back to replacing the app's own location. */
|
||||
export function openArtifactInBrowser(resolved) {
|
||||
const props = artifactBrowserLinkProps(resolved);
|
||||
if (!props) return false;
|
||||
const link = h("a", { ...props, hidden: true });
|
||||
document.body.append(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
return true; // A hand-off was requested; the OS decides which browser handles it.
|
||||
}
|
||||
|
||||
/** One small live-stream badge (LiveBadge.kt): a dot plus the honest word. */
|
||||
export function renderLiveBadge(info) {
|
||||
return h(
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// slash commands, notices and the local rename/hide/seen store. Pure models live
|
||||
// in chat.js and markdown.js; this module owns the DOM and the chat wire wiring.
|
||||
|
||||
import { backChevronIcon, h } from "../dom.js";
|
||||
import { backChevronIcon, h, artifactBrowserLinkProps } from "../dom.js";
|
||||
import { isLocalArtifactLink } from "../artifactNavigation.js";
|
||||
import { formFieldVisible, formFieldValue, formAnswerError, visibleFormAnswers, safeFormURL } from "../chatForms.js";
|
||||
import { readChatStars, writeChatStars } from "../chatStars.js";
|
||||
import { chatModelLabel, chatModelSelectionNote, supportsChatModels } from "../chatModels.js";
|
||||
@@ -3795,13 +3796,17 @@ function renderInlineNodes(spans) {
|
||||
if (span.kind === "strong") return h("strong", {}, ...renderInlineNodes(span.spans));
|
||||
if (span.kind === "emphasis") return h("em", {}, ...renderInlineNodes(span.spans));
|
||||
if (span.kind === "link") {
|
||||
// Only http(s) targets become links: the transcript is untrusted model
|
||||
// Only HTTP(S) or validated same-origin artifact targets become links:
|
||||
// the transcript is untrusted model
|
||||
// output, so a javascript:/data: target is shown as its label, never made
|
||||
// clickable. Nothing is dropped either way.
|
||||
if (/^https?:\/\//i.test(span.url)) {
|
||||
const artifact = isLocalArtifactLink(span.url, globalThis.location?.href);
|
||||
const linkProps = artifact ? artifactBrowserLinkProps(span.url)
|
||||
: /^https?:\/\//i.test(span.url) ? { href: span.url, rel: "noreferrer noopener", target: "_blank" } : null;
|
||||
if (linkProps) {
|
||||
return h(
|
||||
"a",
|
||||
{ class: "md-link", href: span.url, rel: "noreferrer noopener", target: "_blank" },
|
||||
{ class: "md-link", ...linkProps },
|
||||
...renderInlineNodes(span.spans),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// the rendered/raw diff viewer, the artifact viewer, the human-decision sheet,
|
||||
// the shared cancel/retry confirm and the shared Action-failed report.
|
||||
|
||||
import { backChevronIcon, h, canCopyLink, canShare, copyArtifactLink, copyText, shareArtifact } from "../dom.js";
|
||||
import { backChevronIcon, h, canCopyLink, canShare, copyArtifactLink, copyText, shareArtifact, artifactBrowserLinkProps } from "../dom.js";
|
||||
import { changeKindTone, describeError } from "../format.js";
|
||||
import { definitionDocument } from "./stageDefinition.js";
|
||||
import {
|
||||
@@ -663,9 +663,7 @@ function openArtifactViewer(viewable, startIndex, trigger = null) {
|
||||
error.append(
|
||||
h("a", {
|
||||
class: "viewer-external",
|
||||
href: resolved,
|
||||
target: "_blank",
|
||||
rel: "noreferrer",
|
||||
...artifactBrowserLinkProps(resolved),
|
||||
text: `Open ${name} externally`,
|
||||
}),
|
||||
);
|
||||
@@ -752,12 +750,11 @@ function openArtifactViewer(viewable, startIndex, trigger = null) {
|
||||
}
|
||||
if (resolved) {
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "viewer-action",
|
||||
type: "button",
|
||||
h("a", {
|
||||
class: "viewer-action browser-button",
|
||||
...artifactBrowserLinkProps(resolved),
|
||||
"data-viewer-focus": "open",
|
||||
text: "Open",
|
||||
onclick: () => window.open(resolved, "_blank", "noopener,noreferrer"),
|
||||
text: "Open in browser",
|
||||
}),
|
||||
h("button", {
|
||||
class: "viewer-action",
|
||||
|
||||
+25
-49
@@ -3,7 +3,7 @@
|
||||
// the run's artifact gallery. Pure models live in runDetail.js, changes.js,
|
||||
// artifacts.js and actions.js; dialogs are delegated to dialogs.js.
|
||||
|
||||
import { backChevronIcon, h, kvMono, canCopyLink, canShare, copyArtifactLink, shareArtifact } from "../dom.js";
|
||||
import { backChevronIcon, h, kvMono, canCopyLink, canShare, copyArtifactLink, shareArtifact, artifactBrowserLinkProps, openArtifactInBrowser } from "../dom.js";
|
||||
import { isExecuting, changeKindTone, describeError } from "../format.js";
|
||||
import { resolveArtifactUrl } from "../serverUrl.js";
|
||||
import { runStateOf, runStatusLabel } from "../runs.js";
|
||||
@@ -280,9 +280,7 @@ function auditArtifact(step, name, emptyMessage) {
|
||||
toggle,
|
||||
h("a", {
|
||||
class: "audit-doc-open",
|
||||
href: resolved,
|
||||
target: "_blank",
|
||||
rel: "noreferrer",
|
||||
...artifactBrowserLinkProps(resolved),
|
||||
text: "Open raw file",
|
||||
}),
|
||||
);
|
||||
@@ -324,9 +322,7 @@ function auditSession(step) {
|
||||
{ class: "audit-doc-bar" },
|
||||
h("a", {
|
||||
class: "audit-doc-open",
|
||||
href: resolved,
|
||||
target: "_blank",
|
||||
rel: "noreferrer",
|
||||
...artifactBrowserLinkProps(resolved),
|
||||
text: "Open raw file",
|
||||
}),
|
||||
),
|
||||
@@ -837,16 +833,11 @@ function renderVerdictBlock(step) {
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** One inline artifact reference in a verdict reason (viewer files open the viewer). */
|
||||
/** Open references in the browser; preview is an explicit gallery action. */
|
||||
function renderVerdictLink(text, artifact, step) {
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
if (!resolved) return h("span", { class: "verdict-link disabled", text });
|
||||
const link = h("a", { class: "verdict-link", href: resolved, target: "_blank", rel: "noreferrer", text });
|
||||
link.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
openArtifactFromVerdict(artifact, step, resolved, link);
|
||||
});
|
||||
return link;
|
||||
return h("a", { class: "verdict-link", ...artifactBrowserLinkProps(resolved), text });
|
||||
}
|
||||
|
||||
/** One compact chip naming a referenced artifact. */
|
||||
@@ -857,24 +848,10 @@ function renderVerdictRef(artifact, step) {
|
||||
type: "button",
|
||||
text: artifact.name || "(unnamed artifact)",
|
||||
});
|
||||
chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved, chip));
|
||||
chip.addEventListener("click", () => openArtifactInBrowser(resolved));
|
||||
return chip;
|
||||
}
|
||||
|
||||
/** Open a referenced artifact: viewer-selectable files in the viewer, others externally. */
|
||||
function openArtifactFromVerdict(artifact, step, resolved, trigger = null) {
|
||||
if (!resolved) return;
|
||||
const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts: presentedArtifacts(step) };
|
||||
const viewable = pagedArtifacts([group]);
|
||||
const viewerIndexOf = viewerIndexByUrl([group]);
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
if (isViewerArtifact(artifact.content_type, artifact.name) && at != null) {
|
||||
openArtifactViewer(viewable, at, trigger);
|
||||
} else {
|
||||
window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
}
|
||||
|
||||
/** Open the stage pane for one visit of a stage; the controller moves focus in. */
|
||||
function openStagePane(stageKey, visitIndex, { updateRoute = true } = {}) {
|
||||
state.runStagePane = { stageKey, visitIndex };
|
||||
@@ -1130,12 +1107,10 @@ function renderArtifactListRow(artifact, viewable, viewerIndexOf) {
|
||||
open.append(h("span", { class: "artifact-kind", text: artifactKindLabel(kind) }));
|
||||
open.append(h("span", { class: "artifact-list-name", text: name }));
|
||||
open.append(h("span", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }));
|
||||
open.addEventListener("click", () => {
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
if (opensViewer && at != null) openArtifactViewer(viewable, at, open);
|
||||
else if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
});
|
||||
wrap.append(open, renderTileActions(resolved, media));
|
||||
open.addEventListener("click", () => openArtifactInBrowser(resolved));
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
wrap.append(open, renderTileActions(resolved, media, opensViewer && at != null
|
||||
? (trigger) => openArtifactViewer(viewable, at, trigger) : null, name));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
@@ -1202,18 +1177,18 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
"data-artifact-url": artifact.url ?? "",
|
||||
title: name,
|
||||
});
|
||||
const openViewer = () => {
|
||||
const openViewer = (trigger = tile) => {
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
if (at != null) openArtifactViewer(viewable, at, tile);
|
||||
if (at != null) openArtifactViewer(viewable, at, trigger);
|
||||
};
|
||||
const openTab = () => {
|
||||
if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
if (resolved) openArtifactInBrowser(resolved);
|
||||
};
|
||||
if (kind === ArtifactKind.Image) {
|
||||
const img = h("img", { class: "artifact-thumb", alt: name, loading: "lazy" });
|
||||
if (resolved) img.src = resolved;
|
||||
tile.append(img);
|
||||
tile.addEventListener("click", openViewer);
|
||||
tile.addEventListener("click", openTab);
|
||||
} else if (kind === ArtifactKind.Video) {
|
||||
tile.append(
|
||||
h(
|
||||
@@ -1223,7 +1198,7 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
),
|
||||
);
|
||||
tile.append(h("div", { class: "artifact-name", text: name }));
|
||||
tile.addEventListener("click", openViewer);
|
||||
tile.addEventListener("click", openTab);
|
||||
} else {
|
||||
if (opensViewer) {
|
||||
tile.classList.add("artifact-document-tile");
|
||||
@@ -1234,19 +1209,20 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
h("div", { class: "artifact-name", text: name }),
|
||||
h("div", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }),
|
||||
);
|
||||
tile.addEventListener("click", opensViewer ? openViewer : openTab);
|
||||
tile.addEventListener("click", openTab);
|
||||
}
|
||||
wrap.append(tile, renderTileActions(resolved, media));
|
||||
wrap.append(tile, renderTileActions(resolved, media, opensViewer ? openViewer : null, name));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** The compact per-tile actions: icon-only link/share, shown on hover or focus. */
|
||||
function renderTileActions(resolved, media) {
|
||||
function renderTileActions(resolved, media, preview = null, name = "artifact") {
|
||||
const actions = h("div", { class: "artifact-actions" });
|
||||
const stop = (fn) => (event) => {
|
||||
event.stopPropagation();
|
||||
fn();
|
||||
fn(event.currentTarget);
|
||||
};
|
||||
if (preview) actions.append(artifactAction("preview", `Preview in app: ${name}`, !resolved, stop(preview)));
|
||||
if (!media) {
|
||||
actions.append(
|
||||
artifactAction("link", "Copy link", !resolved || !canCopyLink(), stop(() => copyArtifactLink(resolved))),
|
||||
@@ -1275,7 +1251,9 @@ function artifactAction(kind, label, disabled, onclick) {
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.setAttribute("focusable", "false");
|
||||
const path = document.createElementNS(ARTIFACT_SVG_NS, "path");
|
||||
path.setAttribute("d", kind === "link"
|
||||
path.setAttribute("d", kind === "preview"
|
||||
? "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12ZM15 12a3 3 0 1 1-6 0a3 3 0 0 1 6 0Z"
|
||||
: kind === "link"
|
||||
? "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
|
||||
: "M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13");
|
||||
path.setAttribute("fill", "none");
|
||||
@@ -1302,7 +1280,7 @@ function renderSessionExport(step) {
|
||||
row.append(h("span", { text: `Repair: ${repair.status || "partial"} · ${repair.messages || 0} messages. ${repair.diagnostic || ""}` }));
|
||||
const repaired = sessionExportArtifact({ ...step, session_export: repair });
|
||||
const repairedHref = repaired && resolvedArtifactUrl(repaired, state.url);
|
||||
if (repairedHref) row.append(h("a", { href: repairedHref, target: "_blank", rel: "noreferrer", text: "Open repaired export" }));
|
||||
if (repairedHref) row.append(h("a", { ...artifactBrowserLinkProps(repairedHref), text: "Open repaired export" }));
|
||||
wrap.append(row);
|
||||
}
|
||||
const evidence = step?.session_export;
|
||||
@@ -1319,9 +1297,7 @@ function renderSessionExport(step) {
|
||||
wrap.append(
|
||||
h("a", {
|
||||
class: "session-link",
|
||||
href,
|
||||
target: "_blank",
|
||||
rel: "noreferrer",
|
||||
...artifactBrowserLinkProps(href),
|
||||
text: `Open ${file.name || "session.html"}`,
|
||||
}),
|
||||
);
|
||||
|
||||
+5
-22
@@ -2,10 +2,10 @@
|
||||
// routing. Debounce/staleness/ordering/empty-state decisions are pure in
|
||||
// search.js; this module owns the DOM and the route hand-off.
|
||||
|
||||
import { h } from "../dom.js";
|
||||
import { h, openArtifactInBrowser } from "../dom.js";
|
||||
import { describeError } from "../format.js";
|
||||
import { resolveArtifactUrl } from "../serverUrl.js";
|
||||
import { ArtifactKind, artifactKind, isViewerArtifact } from "../artifacts.js";
|
||||
import { ArtifactKind, artifactKind } from "../artifacts.js";
|
||||
import {
|
||||
DEFAULT_SEARCH_KIND,
|
||||
DEFAULT_SEARCH_SORT,
|
||||
@@ -623,31 +623,14 @@ function renderSearchResultRow(hit) {
|
||||
async function routeSearchResult(hit) {
|
||||
const target = searchTarget(hit);
|
||||
if (!target) return;
|
||||
// An artifact hit opens the artifact, not the run/visit that recorded it: media
|
||||
// in the viewer, anything else in a tab. Nothing to show means no navigation.
|
||||
// All artifact types open in the browser. In-app preview is an explicit
|
||||
// gallery action, never an unexpected navigation away from the installed app.
|
||||
if (hit?.kind === "artifact" && hit.artifact?.url) {
|
||||
const artifact = hit.artifact;
|
||||
const resolved = resolveArtifactUrl(state.url, artifact.url);
|
||||
if (!resolved) return;
|
||||
closeSearch();
|
||||
// Media, markdown and text all belong in the viewer, which now renders the
|
||||
// document and offers the trip back to the run; anything else opens raw.
|
||||
if (isViewerArtifact(artifact.content_type, artifact.name)) {
|
||||
rt.views.dialogs.openArtifactViewer(
|
||||
[
|
||||
{
|
||||
url: artifact.url,
|
||||
name: artifact.name,
|
||||
content_type: artifact.content_type,
|
||||
size_bytes: artifact.size_bytes,
|
||||
run_id: artifact.run_id,
|
||||
},
|
||||
],
|
||||
0,
|
||||
);
|
||||
} else {
|
||||
window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
openArtifactInBrowser(resolved);
|
||||
return;
|
||||
}
|
||||
closeSearch();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// A shell cache for an installed Pipelines app. The API (the WebSocket proxy and
|
||||
// artifact files) is never cached; static files prefer the network and fall back
|
||||
// to the last good copy so an installed app still opens when the server is away.
|
||||
const CACHE = "pipelines-shell-v7";
|
||||
const CACHE = "pipelines-shell-v8";
|
||||
const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
@@ -18,7 +18,7 @@ self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))))
|
||||
.then((keys) => Promise.all(keys.filter((key) => key.startsWith("pipelines-shell-") && key !== CACHE).map((key) => caches.delete(key))))
|
||||
.then(() => self.clients.claim()),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// Browser-only regression. Real artifact views/helpers, isolated HTTP fixtures;
|
||||
// Android intents are inspected, never mistaken for a real OS/browser hand-off.
|
||||
import assert from "node:assert/strict";
|
||||
import { createServer } from "node:http";
|
||||
import { readFile, mkdir } from "node:fs/promises";
|
||||
import { resolve, extname } from "node:path";
|
||||
import { launchChrome, eventually } from "./browser.mjs";
|
||||
|
||||
const root = resolve(import.meta.dirname, "..");
|
||||
const out = resolve(process.argv[2] ?? "captures-artifact-browser");
|
||||
await mkdir(out, { recursive: true });
|
||||
const artifactPath = "/artifacts/18/1/public/report.html";
|
||||
const html = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
${["design/tokens/tokens", "base", "shell", "lists", "run-detail", "chat", "dialogs"].map(n => `<link rel="stylesheet" href="/${n}.css">`).join("")}
|
||||
<div class="app-root"><main id="content" style="padding:16px"><h1>Artifact browser hand-off</h1></main></div>
|
||||
<script type="module">
|
||||
import { createModalController } from '/src/modal.js';
|
||||
import { createRunDetailView } from '/src/views/runDetail.js';
|
||||
import { createDialogsView } from '/src/views/dialogs.js';
|
||||
import { createChatView } from '/src/views/chat.js';
|
||||
import { createSearchView } from '/src/views/search.js';
|
||||
import { SearchSequencer } from '/src/search.js';
|
||||
const report={name:'public/report.html',url:'${artifactPath}',content_type:'text/html',size_bytes:70};
|
||||
const documentFile={name:'public/evidence.md',url:'/artifacts/18/1/public/evidence.md',content_type:'text/markdown',size_bytes:50};
|
||||
const session={name:'session.html',url:'/artifacts/18/1/session.html',content_type:'text/html',size_bytes:70};
|
||||
const image={name:'public/pixel.png',url:'/artifacts/18/1/public/pixel.png',content_type:'image/png',size_bytes:68};
|
||||
const step={stage:'research',sequence:1,status:'completed',outcome:'success',artifacts:[report,documentFile,image,session],session_id:'ses_fixture',session_export:{html:'session.html',messages:2,status:'complete'}};
|
||||
const state={url:'ws://'+location.host+'/connect',selectedRunId:18,artifactView:'gallery',runDetail:{id:18,steps:[step]}};
|
||||
window.routes=[];window.handoffs=[];window.copied=[];
|
||||
const rt={state,modal:createModalController(),repo:{},views:{},renderContent:()=>{},selectRun:id=>routes.push(id)};
|
||||
rt.views.chat=createChatView(rt);rt.views.dialogs=createDialogsView(rt);rt.views.runDetail=createRunDetailView(rt);
|
||||
const host=document.querySelector('#content');
|
||||
host.append(rt.views.runDetail.renderArtifactGallery([step]),rt.views.runDetail.renderSessionExport(step));
|
||||
const chat=document.createElement('section');chat.id='chatFixture';chat.append(rt.views.chat.renderMarkdown('[Chat report](${artifactPath})\\n\\n[Unsafe](javascript:alert(1))'));host.append(chat);
|
||||
history.replaceState({selectedRun:18},'', '/runs/18?pipeline=27');
|
||||
document.addEventListener('click',e=>{const link=e.target.closest('a');if(link?.href.startsWith('intent:')){e.preventDefault();handoffs.push({href:link.href,target:link.target,rel:link.rel});}},true);
|
||||
Object.defineProperty(navigator,'clipboard',{configurable:true,value:{writeText:async text=>copied.push(text)}});
|
||||
window.ready=true;
|
||||
window.showList=()=>{state.artifactView='list';const list=document.createElement('section');list.id='listFixture';list.append(rt.views.runDetail.renderArtifactGallery([step]));host.append(list);};
|
||||
window.showSearch=()=>{const target=document.createElement('div');document.body.append(target);Object.assign(state,{searchQuery:'',searchKind:'',searchSort:'relevance',searchResults:[],searchSequencer:new SearchSequencer(),searchActiveIndex:0});const search=createSearchView({...rt,searchHost:target,renderHeader:()=>{},repo:{search:async()=>({results:[{kind:'artifact',target:documentFile.url,artifact:{...documentFile,run_id:18,sequence:1}}]})}});search.openSearch();};
|
||||
</script>`;
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const path = new URL(req.url, "http://fixture").pathname;
|
||||
if (path === "/" || path.startsWith("/runs/")) {
|
||||
res.setHeader("Content-Type", "text/html"); res.end(html); return;
|
||||
}
|
||||
if (path.startsWith("/artifacts/")) {
|
||||
if (path.endsWith('.png')) {res.setHeader('Content-Type','image/png');res.end(Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=','base64'));return;}
|
||||
res.setHeader("Content-Type", path.endsWith(".md") ? "text/markdown" : "text/html");
|
||||
res.setHeader("Content-Security-Policy", "sandbox; default-src 'none'");
|
||||
res.end(path.endsWith(".md") ? "# Fixture evidence\n\nA document preview remains inside the app." : "<!doctype html><title>Fixture report</title><h1>Fixture report</h1>"); return;
|
||||
}
|
||||
const file = resolve(root, `.${path}`);
|
||||
if (!file.startsWith(root + "/")) throw Error("outside fixture");
|
||||
res.setHeader("Content-Type", extname(file) === ".css" ? "text/css" : "text/javascript");
|
||||
res.end(await readFile(file));
|
||||
} catch { res.writeHead(404); res.end(); }
|
||||
});
|
||||
await new Promise(r => server.listen(0, "127.0.0.1", r));
|
||||
const origin = `http://127.0.0.1:${server.address().port}`;
|
||||
let browser;
|
||||
try {
|
||||
browser = await launchChrome({ width: 390, height: 844 });
|
||||
const page = await browser.openPage(origin);
|
||||
await page.waitForSelector(`[data-artifact-name="public/report.html"]`);
|
||||
const appURL = await page.evaluate("location.href");
|
||||
const historyLength = await page.evaluate("history.length");
|
||||
await page.click('[data-artifact-name="public/report.html"]');
|
||||
await eventually(async () => (await fetch(`http://127.0.0.1:${browser.port}/json/list`).then(r => r.json())).some(target => target.url === origin + artifactPath));
|
||||
assert.equal(await page.evaluate("location.href"), appURL);
|
||||
assert.equal(await page.evaluate("history.length"), historyLength);
|
||||
await page.screenshot(resolve(out, "01-app-preserved-after-browser-open.png"));
|
||||
|
||||
const android = await browser.openPage("about:blank");
|
||||
await android.emulateTouch(true);
|
||||
await android.addInitScript(`(() => {
|
||||
Object.defineProperty(navigator,'userAgent',{configurable:true,value:'Mozilla/5.0 (Linux; Android 14) Chrome/130 Mobile Safari/537.36'});
|
||||
const native=window.matchMedia.bind(window);
|
||||
window.matchMedia=q=>q==='(display-mode: standalone)'?{matches:true}:native(q);
|
||||
})()`);
|
||||
await android.goto(origin);
|
||||
await android.waitForSelector('[data-artifact-name="public/report.html"]');
|
||||
const original = await android.evaluate("location.href");
|
||||
await android.click('[data-artifact-name="public/report.html"]');
|
||||
await android.click('#chatFixture a.md-link');
|
||||
await android.click('.session-link');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 3);
|
||||
assert.equal(await android.evaluate("document.querySelectorAll('a[href^=javascript]').length"), 0);
|
||||
assert.equal(await android.evaluate("location.href"), original);
|
||||
await android.click('[data-artifact-name="public/evidence.md"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 4, "Markdown Open must request the browser too");
|
||||
assert.equal(await android.evaluate("!!document.querySelector('.artifact-viewer')"), false);
|
||||
await android.click('[data-artifact-name="public/pixel.png"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 5, "images must not unexpectedly open inside the installed app");
|
||||
await android.click('[aria-label="Preview in app: public/evidence.md"]');
|
||||
await android.waitForSelector('.viewer-markdown');
|
||||
assert.equal(await android.evaluate("location.href"), original);
|
||||
const props = await android.evaluate("(() => {const a=document.querySelector('[data-viewer-focus=open]');return {tag:a.tagName,text:a.textContent,href:a.href,target:a.target,rel:a.rel};})()");
|
||||
assert.equal(props.tag, "A"); assert.equal(props.text, "Open in browser");
|
||||
assert.match(props.href, /^intent:/); assert.equal(props.target, "_blank"); assert.ok(props.rel.includes("noopener"));
|
||||
await android.click('[data-viewer-focus=open]');
|
||||
await android.click('[data-viewer-focus=copy]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 6);
|
||||
assert.equal(await android.evaluate("copied[0]"), origin + "/artifacts/18/1/public/evidence.md");
|
||||
assert.equal(await android.evaluate("location.href"), original);
|
||||
for (const width of [390, 420]) {
|
||||
await android.resize(width,844);
|
||||
const fits = await android.evaluate("(() => {const p=document.querySelector('.viewer-panel').getBoundingClientRect();return [...document.querySelectorAll('.viewer-action')].every(a=>{const r=a.getBoundingClientRect();return r.left>=p.left && r.right<=p.right;}) && document.documentElement.scrollWidth<=innerWidth;})()");
|
||||
assert.equal(fits,true,"viewer actions must stay reachable without widening the mobile app");
|
||||
await android.screenshot(resolve(out, `02-installed-android-browser-action-${width}.png`));
|
||||
}
|
||||
await android.pressKey("Escape");
|
||||
await android.evaluate('showList()');
|
||||
await android.click('#listFixture .artifact-list-open[aria-label="Open public/evidence.md"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 7);
|
||||
await android.evaluate('showSearch()');
|
||||
await android.waitForSelector('#searchInput');await android.fill('#searchInput','evidence');
|
||||
await android.waitForSelector('.search-row[data-kind=artifact]');await android.click('.search-row[data-kind=artifact]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 8, "search results must use the same browser hand-off");
|
||||
assert.equal(await android.evaluate("location.href"), original);
|
||||
assert.deepEqual(await android.evaluate("routes"), []);
|
||||
console.log("PASS: real browser tab opens while app URL/history stay intact; installed-Android VIEW intents cover tiles, chat, session and viewer actions; previews and Copy keep their original behavior. Android OS launch is not tested.");
|
||||
} finally {
|
||||
await browser?.close();
|
||||
await new Promise(r => server.close(r));
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { artifactBrowserLinkProps, isLocalArtifactLink } from "../src/artifactNavigation.js";
|
||||
|
||||
const base = "https://pipelines.test/runs/18";
|
||||
const environment = (userAgent, mode = "browser") => ({
|
||||
location: { href: base }, navigator: { userAgent },
|
||||
matchMedia: (query) => ({ matches: query === `(display-mode: ${mode})` }),
|
||||
});
|
||||
|
||||
test("ordinary browsers and iOS request a separate isolated context", () => {
|
||||
for (const env of [environment("Desktop Chrome"), environment("Android Chrome"),
|
||||
{ ...environment("iPhone Safari"), navigator: { userAgent: "iPhone Safari", standalone: true } }]) {
|
||||
const props = artifactBrowserLinkProps("/artifacts/18/2/public/report.html", env);
|
||||
assert.equal(props.href, "https://pipelines.test/artifacts/18/2/public/report.html");
|
||||
assert.equal(props.target, "_blank");
|
||||
for (const relation of ["external", "noopener", "noreferrer"]) assert.ok(props.rel.includes(relation));
|
||||
}
|
||||
});
|
||||
|
||||
test("installed Android apps request a browser VIEW hand-off, not a captured app navigation", () => {
|
||||
for (const mode of ["standalone", "fullscreen"]) {
|
||||
const props = artifactBrowserLinkProps("/artifacts/18/2/public/report.html?download=0#section", environment("Android Chrome", mode));
|
||||
assert.match(props.href, /^intent:\/\//);
|
||||
const marker = props.href.lastIndexOf("#Intent;");
|
||||
const fields = props.href.slice(marker);
|
||||
assert.ok(fields.includes("action=android.intent.action.VIEW;"));
|
||||
assert.ok(fields.includes("category=android.intent.category.BROWSABLE;"));
|
||||
assert.ok(fields.includes("package=com.android.chrome;"), "do not resolve back into the installed WebAPK");
|
||||
const original = "https:" + props.href.slice("intent:".length, marker);
|
||||
assert.equal(original, "https://pipelines.test/artifacts/18/2/public/report.html?download=0#section");
|
||||
const fallback = fields.match(/S\.browser_fallback_url=([^;]+);/)[1];
|
||||
assert.equal(decodeURIComponent(fallback), original);
|
||||
assert.equal(props.target, "_blank");
|
||||
}
|
||||
});
|
||||
|
||||
test("document fragments cannot inject intent actions or packages", () => {
|
||||
const props = artifactBrowserLinkProps("/artifacts/a.html#Intent;package=bad.app;action=unsafe;end", environment("Android", "standalone"));
|
||||
const fields = props.href.slice(props.href.lastIndexOf("#Intent;"));
|
||||
assert.ok(fields.includes(";package=com.android.chrome;"));
|
||||
assert.ok(!fields.includes(";package=bad.app;"));
|
||||
assert.ok(!fields.includes(";action=unsafe;"));
|
||||
assert.ok(fields.includes(";action=android.intent.action.VIEW;"));
|
||||
});
|
||||
|
||||
test("identified Android browser families do not get sent into the WebAPK", () => {
|
||||
for (const [agent,pkg] of [["Android EdgA/130","com.microsoft.emmx"],["Android SamsungBrowser/25","com.sec.android.app.sbrowser"],["Android OPR/80","com.opera.browser"],["Android Firefox/130","org.mozilla.firefox"]]) {
|
||||
const props=artifactBrowserLinkProps("/artifacts/a.html",environment(agent,"standalone"));
|
||||
assert.ok(props.href.includes(`;package=${pkg};`));
|
||||
}
|
||||
});
|
||||
|
||||
test("artifact hand-offs reject blank, executable and credential-bearing URLs", () => {
|
||||
for (const url of [null, "", " ", "javascript:alert(1)", "data:text/html,bad", "file:///secret", "https://user:pass@pipelines.test/artifacts/a"]) {
|
||||
assert.equal(artifactBrowserLinkProps(url, environment("Android", "standalone")), null);
|
||||
}
|
||||
});
|
||||
|
||||
test("chat recognizes only genuine same-origin artifact links", () => {
|
||||
for (const url of ["/artifacts/18/2/public/report.html", "https://pipelines.test/artifacts/a.html"]) assert.equal(isLocalArtifactLink(url, base), true);
|
||||
for (const url of ["/runs/18", "//evil.test/artifacts/a", "/artifacts/../../admin", "https://pipelines.test.evil/artifacts/a", "javascript:alert(1)"]) assert.equal(isLocalArtifactLink(url, base), false);
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import vm from "node:vm";
|
||||
|
||||
test("shell updates retain unrelated caches and the current app cache", async () => {
|
||||
const handlers = new Map();
|
||||
const deleted = [];
|
||||
let activation;
|
||||
vm.runInNewContext(await readFile(new URL("../sw.js", import.meta.url), "utf8"), {
|
||||
self: { addEventListener: (type, handler) => handlers.set(type, handler), clients: { claim: async () => {} } },
|
||||
caches: { keys: async () => ["pipelines-shell-v7", "pipelines-shell-v8", "unrelated-user-cache"], delete: async (key) => deleted.push(key) },
|
||||
});
|
||||
handlers.get("activate")({ waitUntil: (promise) => { activation = promise; } });
|
||||
await activation;
|
||||
assert.deepEqual(deleted, ["pipelines-shell-v7"]);
|
||||
});
|
||||
Reference in New Issue
Block a user