Web Platform Prototype · Edge + Multi-Window State

Document Picture-in-Picture Coprocessor

A persistent floating sidecar built purely with origin-scoped web APIs: window.documentPictureInPicture hosts an adaptive tool pane, Navigation API handles same-document route transitions across edge-rendered HTML pages, and BroadcastChannel synchronizes checklists and pinned notes across windows and tabs.

Coprocessor Surface
Checking capability…
Navigation Mode
Detecting Navigation API…
Channel Bus
pip_coprocessor_bus
Active Route
/workspace/audit
Problem & Hypothesis

In-page helper panels tear down on page navigation, pushing tools into browser extensions. Combining documentPictureInPicture, BroadcastChannel, the Navigation API, and CSS @container queries sustains a persistent cross-route companion on a normal web origin.

Confirm Signal

Navigating across /, /workspace/specs, /workspace/audit, and /workspace/notes updates the floating Document PiP (or docked) companion immediately without losing pinned notes, checklist state, or duplicating bus listeners.

Falsify Signal

User-activation gates on requestWindow(), framed embed restrictions, or unsupported browsers and mobile viewports force heavy reliance on the docked BroadcastChannel fallback.

3 Things To Try

Execute live runtime transitions directly or trigger them from the floating pane.

1. Open Floating Document PiP / Docked Coprocessor

Launch the 420×520 always-on-top Document PiP window (in Chromium) or focus the Docked BroadcastChannel pane if PiP is unavailable or framed.

2. Navigate Across Workspace Routes & Watch Route Sync

Step across /, /workspace/specs, /workspace/audit, and /workspace/notes via Navigation API or open a second tab to verify live sync.

3. Pin Document Findings & Run Checks From Inside Coprocessor

Pin the first span from the active route and execute a checklist verification, then watch frames arrive in the Wire Inspector below.

Open Route in New Tab
/workspace/audit Security & Policy Inspector

DOM, CSP & Origin Audit

Inspects edge response headers, Content-Security-Policy frame boundaries, and container-query adaptation rules.

Inspectable Document Spans

Pin any span to transmit a PIN_NOTE frame over pip_coprocessor_bus.
CSP Frame Policy security
frame-ancestors 'self' https://aifoc.us https://*.aifoc.us http://localhost:* http://127.0.0.1:*; allows blog embedding while blocking arbitrary origins.

Inside cross-origin iframes where Document PiP is restricted, the client switches cleanly to Docked BroadcastChannel Mode.

Not pinned
DOM Construction security
All dynamic spans, wire frames, and pinned notes are created with document.createElement() and .textContent without HTML string parsing.

Avoiding innerHTML removes DOM injection risks when echoing route titles, notes, or BroadcastChannel frames.

Not pinned
CSS Container Queries layout
The coprocessor root declares container-type: inline-size so @container (max-width: 380px) collapses multi-column grids into single-column stacks.

Container-width styling makes the pane adapt consistently inside a 420px PiP window or a docked sidebar.

Not pinned

Route Prompt & Verification Checklist

  • Validate edge CSP headers pending

    Inspect Content-Security-Policy for script-src 'self' and the frame-ancestors allowlist.

    Expected signal: CSP header verified

  • Confirm zero innerHTML DOM writes pending

    Verify dynamic views build nodes exclusively via createElement, createTextNode, and textContent.

    Expected signal: Safe DOM construction

  • Test docked fallback mode pending

    Verify #docked-coprocessor retains full functionality when documentPictureInPicture is unavailable.

    Expected signal: Docked mode operational

Synchronized Notes Ledger

No notes pinned yet. Pin a document span above or submit a custom note from the Coprocessor pane.

BroadcastChannel Wire Inspector (pip_coprocessor_bus) 0 frames
Initializing BroadcastChannel listener on pip_coprocessor_bus...
Live Coprocessor State & Container Query Metrics seq 0
{}
Edge HTTP Headers, CSP & Route Descriptor (GET /api/routes) /workspace/audit
Loading /api/routes descriptor...
Runtime flow between Multi-Page Host Routes, BroadcastChannel Bus, and Persistent Document PiP Window Edge-rendered workspace routes connect via BroadcastChannel pip_coprocessor_bus to either a 420 by 520 Document Picture-in-Picture window or a docked fallback pane adapted with CSS container queries. Multi-Page Host Routes Cloudflare Worker SSR HTML / /workspace/specs /workspace/audit /workspace/notes navigation.on("navigate") or peer tabs on full reload Origin-scoped DOM + CSP ROUTE_SYNC PIN / CHECK BroadcastChannel Bus pip_coprocessor_bus validateCoprocessorMessage() applyCoprocessorState() Same-origin structured clone STATE COMMANDS Persistent Coprocessor Document PiP Window requestWindow({ 420 × 520 }) Docked Fallback Mode #docked-coprocessor (all browsers) @container (max-width: 380px)
Architecture boundary: edge-rendered HTML documents synchronize via BroadcastChannel("pip_coprocessor_bus") with a persistent Document PiP window or docked fallback pane styled by CSS Container Queries.
How This Is Set Up

Origin-Scoped Companion Window vs. Browser Extension

Keeping a persistent companion tool window synchronized across /workspace/* transitions using standard origin-scoped Web APIs instead of a Manifest V3 extension.

Extension baseline (Manifest V3)
// manifest.json + extension service worker
{
  "manifest_version": 3,
  "permissions": ["sidePanel", "tabs", "storage"],
  "host_permissions": ["https://workspace.example/*"],
  "background": { "service_worker": "sw.js" }
}
// background/sw.js
chrome.tabs.onUpdated.addListener((tabId, info) => {
  if (info.url) chrome.runtime.sendMessage({ tabId, url: info.url });
});
Origin-scoped Web APIs (this lab)
// public/app.js — Document PiP + BroadcastChannel + Navigation API
const hostChannel = new BroadcastChannel("pip_coprocessor_bus");
const pipWin = await window.documentPictureInPicture.requestWindow({
  width: 420,
  height: 520,
});
copyStylesheetsToPipWindow(pipWin.document);
createCoprocessorPane(pipWin.document, pipWin.document.body, "pip", options);

window.navigation.addEventListener("navigate", (event) => {
  const destUrl = new URL(event.destination.url);
  const route = getRouteByPath(destUrl.pathname);
  if (route && event.canIntercept) {
    event.intercept({ handler: () => handleInterceptedRoute(route, destUrl, event.signal) });
  }
});
Page Markup, Protocol Schema & Container Queries

Matches src/worker.ts, public/lib/coprocessor-protocol.js, public/pip-pane.css, and public/app.js.

<!-- 1. Edge-rendered Workspace Shell (src/worker.ts -> renderPageHtml) -->
<link rel="stylesheet" href="/styles.css">
<link rel="stylesheet" href="/pip-pane.css">
<div class="workspace-grid">
  <main id="workspace-main" data-route-path="/" data-route-title="Coprocessor Workspace Overview">...</main>
  <aside id="docked-coprocessor" class="coprocessor-shell" aria-label="Coprocessor Pane"></aside>
</div>
<script type="module" src="/app.js"></script>

// 2. Protocol Schema & @container Rules (coprocessor-protocol.js + pip-pane.css)
export const CHANNEL_NAME = "pip_coprocessor_bus";
export const VALID_MESSAGE_TYPES = ["ROUTE_SYNC", "PIN_NOTE", "RUN_CHECK", "CLEAR_NOTES", "PING_COPROCESSOR"];
export const VALID_SOURCES = ["host", "pip", "docked", "tab"];
/* public/pip-pane.css */
.coprocessor-root { container: coprocessor / inline-size; display: grid; gap: 0.8rem; padding: 0.95rem; }
.coprocessor-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.45rem; }
@container (max-width: 380px) {
  .coprocessor-header, .coprocessor-toolbar { flex-direction: column; align-items: stretch; }
  .coprocessor-stats, .coprocessor-check-row, .coprocessor-note-form { grid-template-columns: minmax(0, 1fr); }
}
Same-Document Route Swap & Reducer Contract
// public/app.js — Navigation API handler swaps SSR #workspace-main without closing PiP
const response = await fetch(destUrl.pathname, { signal, headers: { "X-Coprocessor-Nav": "navigation-api" } });
const parsedDoc = new DOMParser().parseFromString(await response.text(), "text/html");
const nextMain = parsedDoc.getElementById("workspace-main");
const currentMain = document.getElementById("workspace-main");
if (nextMain && currentMain) {
  currentMain.replaceWith(document.importNode(nextMain, true));
}
dispatchFromHost({ type: "ROUTE_SYNC", source: "host", timestamp: Date.now(), path: route.path, navigationMode: "navigation-api" });
What is avoided

Manifest V3 packaging, store review, host permissions, and an extension background service worker just to keep a companion panel alive across origin routes.

What is explicit

Opener-owned documentPictureInPicture.requestWindow() lifecycle, schema validation in validateCoprocessorMessage(), Navigation API DOM swaps, and #docked-coprocessor fallback.

Platform limits tested

window.documentPictureInPicture is Chromium-only and disallowed inside cross-origin iframes; full reloads close the opener-owned PiP window, so peer tabs rehydrate via localStorage and BroadcastChannel.