Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8334eca
fix(browser): retire superseded observation runs and verify recovery
elacity2822-beep Oct 16, 2026
e0d2cc6
fix(browser): retain input ownership and report uncertain delivery
elacity2822-beep Oct 16, 2026
b21b93a
perf(browser): reuse CDP domain preparation within each connection
elacity2822-beep Oct 16, 2026
ffd7694
Merge remote-tracking branch 'origin/develop' into fix/review-browser…
elacity2822-beep Oct 17, 2026
7659a27
Merge branch 'fix/review-browser-lifecycle' into fix/review-browser-i…
elacity2822-beep Oct 17, 2026
a5e72e8
Merge branch 'fix/review-browser-input-ownership' into fix/review-bro…
elacity2822-beep Oct 17, 2026
ab90ce1
test(browser): keep control smoke aligned with relay-only ICE
elacity2822-beep Oct 17, 2026
9a86d3a
Run Browser lifecycle smokes in the behavior gate
SashaMIT Oct 17, 2026
f089a17
Retire Browser touch ownership and preserve uncertain input errors
SashaMIT Oct 17, 2026
293fd00
Run the Browser control process smoke in the behavior gate
SashaMIT Oct 17, 2026
21e7f84
Merge reviewed Browser parent updates
SashaMIT Oct 17, 2026
745fff4
Merge reviewed Browser input and lifecycle updates
SashaMIT Oct 17, 2026
0a466c9
Merge current develop integration into browser-lifecycle
SashaMIT Oct 18, 2026
bfb0258
Reuse the platform-neutral Home link test fixture
SashaMIT Oct 18, 2026
23256cd
Merge current develop integration into browser-input-ownership
SashaMIT Oct 18, 2026
2e72ece
Merge current develop integration into browser-cdp-preparation
SashaMIT Oct 18, 2026
112d258
Merge refreshed develop integration into browser-cdp-preparation
SashaMIT Oct 18, 2026
d396a5c
Merge refreshed develop integration into browser-lifecycle
SashaMIT Oct 18, 2026
38ca016
Merge refreshed develop integration into browser-input-ownership
SashaMIT Oct 18, 2026
d45d7e8
Merge current develop with canonical Home-link fixture
SashaMIT Oct 18, 2026
9fc519f
Merge current develop with canonical Home-link fixture
SashaMIT Oct 18, 2026
cdfa93e
Merge current develop with canonical Home-link fixture
SashaMIT Oct 18, 2026
5fc7165
Remove redundant CDP readiness reset on close
SashaMIT Oct 18, 2026
8c27d0e
Merge current develop into Browser lifecycle review
SashaMIT Oct 19, 2026
bf519a7
Merge refreshed Browser lifecycle into input ownership review
SashaMIT Oct 19, 2026
1a5770f
Merge refreshed Browser input into CDP preparation review
SashaMIT Oct 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 97 additions & 29 deletions capsules/browser/browser/browser-input-surface.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function plainTextFromClipboardEvent(event) {
}

export function bindBrowserInputSurface({
captureViewerOwnerGuard,
copyRemoteClipboardToHost,
friendlyOpenError,
getCurrentPage,
Expand All @@ -28,14 +29,26 @@ export function bindBrowserInputSurface({
unlockRemoteAudioFromGesture,
}) {
let wheelTimer = 0;
let wheelDelta = { x: 0, y: 0 };
let wheelBatch = null;
let touchPanState = null;
let suppressSyntheticClickUntil = 0;
const hostModifierState = {
control: false,
meta: false,
};

function retireTouchPan() {
const retired = touchPanState;
// Drop ownership before releasing capture: lostpointercapture may run now.
touchPanState = null;
if (!retired) return null;
suppressSyntheticClickUntil = Date.now() + 700;
if (renderPanel.hasPointerCapture?.(retired.pointerId)) {
renderPanel.releasePointerCapture(retired.pointerId);
}
return retired;
}

function focusKeyboardCapture() {
const target = keyboardCapture || renderPanel;
target.focus({ preventScroll: true });
Expand Down Expand Up @@ -187,7 +200,10 @@ export function bindBrowserInputSurface({
};
}

function sendClickFromEvent(event) {
function sendClickFromEvent(event, ownerActive = captureViewerOwnerGuard()) {
if (!ownerActive()) {
return;
}
unlockRemoteAudioFromGesture();
const point = browserPointFromEvent(event);
if (!point) {
Expand All @@ -199,7 +215,9 @@ export function bindBrowserInputSurface({
{ type: "click", x: point.x, y: point.y },
{ history: "push" },
).catch((error) => {
showStatus(friendlyOpenError(error), { sticky: true });
if (ownerActive()) {
showStatus(friendlyOpenError(error), { sticky: true });
}
});
}

Expand All @@ -212,29 +230,60 @@ export function bindBrowserInputSurface({
}

function queueWheelInput(point, deltaX, deltaY) {
wheelDelta.x += deltaX;
wheelDelta.y += deltaY;
if (wheelBatch && !wheelBatch.ownerActive()) {
window.clearTimeout(wheelTimer);
wheelBatch = null;
}
if (!wheelBatch) {
const ownerActive = captureViewerOwnerGuard();
if (!ownerActive()) {
return;
}
wheelBatch = { ownerActive, x: 0, y: 0, point };
}
const batch = wheelBatch;
batch.x += deltaX;
batch.y += deltaY;
batch.point = point;
window.clearTimeout(wheelTimer);
wheelTimer = window.setTimeout(() => {
const delta = wheelDelta;
wheelDelta = { x: 0, y: 0 };
if (wheelBatch !== batch) {
return;
}
wheelTimer = 0;
wheelBatch = null;
if (!batch.ownerActive()) {
return;
}
sendBrowserInput(
{
type: "wheel",
x: point?.x,
y: point?.y,
delta_x: delta.x,
delta_y: delta.y,
x: batch.point?.x,
y: batch.point?.y,
delta_x: batch.x,
delta_y: batch.y,
},
{ history: "replace" },
).catch((error) =>
showStatus(friendlyOpenError(error), { sticky: true }),
);
).catch((error) => {
if (batch.ownerActive()) {
showStatus(friendlyOpenError(error), { sticky: true });
}
});
}, WHEEL_FLUSH_MS);
}

function isSyntheticTouchClick(event) {
// Touch and pen taps dispatch once from pointerup under the captured
// owner. Their later click event cannot capture a replacement owner.
if (event.pointerType === "touch" || event.pointerType === "pen" ||
event.sourceCapabilities?.firesTouchEvents === true) return true;
// Older hosts report compatibility clicks without pointer provenance.
// A known mouse remains independent from that short touch fallback.
return event.pointerType !== "mouse" && Date.now() < suppressSyntheticClickUntil;
}

remoteVideo.addEventListener("click", (event) => {
if (Date.now() < suppressSyntheticClickUntil) {
if (isSyntheticTouchClick(event)) {
event.preventDefault();
return;
}
Expand All @@ -243,7 +292,7 @@ export function bindBrowserInputSurface({
});

renderPanel.addEventListener("click", (event) => {
if (Date.now() < suppressSyntheticClickUntil) {
if (isSyntheticTouchClick(event)) {
event.preventDefault();
return;
}
Expand All @@ -262,13 +311,24 @@ export function bindBrowserInputSurface({
if (event.pointerType !== "touch" && event.pointerType !== "pen") {
return;
}
// An owner that has retired cannot reserve the next page's gesture.
if (touchPanState && !touchPanState.ownerActive()) retireTouchPan();
// The current owner keeps its first pointer until that gesture ends.
if (touchPanState) {
return;
}
if (!getCurrentPage()) {
return;
}
const ownerActive = captureViewerOwnerGuard();
if (!ownerActive()) {
return;
}
event.preventDefault();
focusKeyboardCapture();
touchPanState = {
pointerId: event.pointerId,
ownerActive,
x: event.clientX,
y: event.clientY,
moved: false,
Expand All @@ -283,12 +343,15 @@ export function bindBrowserInputSurface({
(event) => {
if (
!touchPanState ||
event.pointerId !== touchPanState.pointerId ||
!getCurrentPage()
event.pointerId !== touchPanState.pointerId
) {
return;
}
event.preventDefault();
if (!touchPanState.ownerActive() || !getCurrentPage()) {
retireTouchPan();
return;
}
const dx = touchPanState.x - event.clientX;
const dy = touchPanState.y - event.clientY;
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) {
Expand All @@ -305,26 +368,28 @@ export function bindBrowserInputSurface({
renderPanel.addEventListener(
"pointerup",
(event) => {
// A retired finger can remain down longer than the fallback window.
// Renew it at release without taking ownership from a fresh pointer.
if (event.pointerType === "touch" || event.pointerType === "pen") {
suppressSyntheticClickUntil = Date.now() + 700;
}
if (!touchPanState || event.pointerId !== touchPanState.pointerId) {
return;
}
event.preventDefault();
renderPanel.releasePointerCapture?.(event.pointerId);
const moved = touchPanState.moved;
touchPanState = null;
suppressSyntheticClickUntil = Date.now() + 700;
const { moved, ownerActive } = retireTouchPan();
if (!moved) {
sendClickFromEvent(event);
sendClickFromEvent(event, ownerActive);
}
},
{ passive: false },
);

renderPanel.addEventListener("pointercancel", (event) => {
if (touchPanState?.pointerId === event.pointerId) {
touchPanState = null;
}
});
for (const type of ["pointercancel", "lostpointercapture"]) {
renderPanel.addEventListener(type, (event) => {
if (touchPanState?.pointerId === event.pointerId) retireTouchPan();
});
}

renderPanel.addEventListener(
"wheel",
Expand All @@ -333,9 +398,12 @@ export function bindBrowserInputSurface({
return;
}
unlockRemoteAudioFromGesture();
const point = browserPointFromEvent(event);
if (!point) {
return;
}
event.preventDefault();
focusKeyboardCapture();
const point = browserPointFromEvent(event);
queueWheelInput(point, event.deltaX, event.deltaY);
},
{ passive: false },
Expand Down
Loading
Loading