Remove shareable invitation links
Codes are exchanged by copy and paste again. The URL fragment intake, the invitation dialog, the BroadcastChannel answer relay and the Share link / Copy link controls are gone, along with their tests, browser check scenarios and design doc. Code fields no longer accept links. The compressed HC1 codes with typed offers/answers and echoed refs stay. An optional signaling backend is the intended way to simplify the exchange instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f320bfb541
commit
a5935a8324
16 files changed
+57
-602
No files matched your search
@@ -49,7 +49,6 @@ interface ProtocolResults {
|
||||
'Browser.setDownloadBehavior': object;
|
||||
'Target.createTarget': { targetId: string };
|
||||
'Target.attachToTarget': { sessionId: string };
|
||||
'Target.closeTarget': object;
|
||||
'Runtime.enable': object;
|
||||
'Page.enable': object;
|
||||
'Page.navigate': object;
|
||||
@@ -100,11 +99,9 @@ async function wait(session: string, check: () => unknown) {
|
||||
const result = await call('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true }, session);
|
||||
if (result.exceptionDetails) throw new Error(JSON.stringify(result.exceptionDetails));
|
||||
}
|
||||
const targets = new Map<string, string>();
|
||||
async function page(url = origin) {
|
||||
const { targetId } = await call('Target.createTarget', { url: 'about:blank' });
|
||||
const { sessionId } = await call('Target.attachToTarget', { targetId, flatten: true });
|
||||
targets.set(sessionId, targetId);
|
||||
await call('Runtime.enable', {}, sessionId);
|
||||
await call('Page.enable', {}, sessionId);
|
||||
// Background tabs otherwise skip focus/blur events, which the name editor relies on.
|
||||
@@ -117,8 +114,7 @@ async function page(url = origin) {
|
||||
if (turn) await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${forceRelay.toString()})(${JSON.stringify(transport)})` }, sessionId);
|
||||
await call('Page.navigate', { url }, sessionId);
|
||||
for (let n = 0; n < 100; n++) {
|
||||
// The app removes invitation fragments from the address bar.
|
||||
try { if (await evaluate(sessionId, (expected: string) => location.href.startsWith(expected) && document.readyState === 'complete', url.split('#')[0]!)) break; }
|
||||
try { if (await evaluate(sessionId, (expected: string) => location.href.startsWith(expected) && document.readyState === 'complete', url)) break; }
|
||||
catch (err) { if (!(err instanceof Error) || !err.message.includes('context')) throw err; }
|
||||
await new Promise(resolve => setTimeout(resolve, 20));
|
||||
}
|
||||
@@ -143,7 +139,6 @@ const screenshot = async (session: string, name: string) => {
|
||||
const { data } = await call('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false }, session);
|
||||
await writeFile(join(screenshotDirectory, name + '.png'), Buffer.from(data, 'base64'));
|
||||
};
|
||||
const closePage = (session: string) => call('Target.closeTarget', { targetId: targets.get(session) });
|
||||
const dialogText = (session: string) => evaluate(session, () => document.querySelector('dialog[open]')?.textContent ?? '');
|
||||
const click = (session: string, label: string) => evaluate(session, (label: string) => window.__hellcon.click(label), label);
|
||||
const input = (session: string, selector: string, value: string) => evaluate(session, (selector: string, value: string) => window.__hellcon.input(selector, value), selector, value);
|
||||
@@ -151,30 +146,12 @@ const enableTurn = (session: string) => evaluate(session, () => {
|
||||
const checkbox = window.__hellcon.element<HTMLInputElement>('.checkbox input');
|
||||
if (!checkbox.checked) checkbox.click();
|
||||
});
|
||||
let checkedCodeLayout = false;
|
||||
async function connect(sender: string, receiver: string, size: number, changedIdentity = false) {
|
||||
await evaluate(sender, (size: number) => window.__hellcon.chooseFile(size, 'browser-test.bin'), size);
|
||||
await input(sender, '#stun-provider', provider);
|
||||
await input(receiver, '#stun-provider', provider);
|
||||
if (turn) { await enableTurn(sender); await enableTurn(receiver); }
|
||||
await click(sender, 'Create code'); await wait(sender, () => !!document.querySelector('#output-code'));
|
||||
if (!checkedCodeLayout) {
|
||||
const layout = await evaluate(sender, () => {
|
||||
const details = window.__hellcon.element<HTMLDetailsElement>('.code-details');
|
||||
const closedByDefault = !details.open;
|
||||
details.open = true;
|
||||
const code = window.__hellcon.element<HTMLTextAreaElement>('#output-code').getBoundingClientRect();
|
||||
const copy = window.__hellcon.element<HTMLButtonElement>('.code-entry button').getBoundingClientRect();
|
||||
const answer = window.__hellcon.element<HTMLTextAreaElement>('#answer-input').getBoundingClientRect();
|
||||
const connect = window.__hellcon.element<HTMLButtonElement>('#answer-input + button').getBoundingClientRect();
|
||||
details.open = false;
|
||||
return { closedByDefault, codeGap: copy.top - code.bottom, answerGap: connect.top - answer.bottom, codeWidth: code.width, answerWidth: answer.width };
|
||||
});
|
||||
assert.equal(layout.closedByDefault, true, 'Code alternative starts collapsed');
|
||||
assert.ok(Math.abs(layout.codeGap - layout.answerGap) < 1, 'Code and answer buttons have matching spacing');
|
||||
assert.ok(Math.abs(layout.codeWidth - layout.answerWidth) < 1, 'Code and answer fields have matching width');
|
||||
checkedCodeLayout = true;
|
||||
}
|
||||
const offer = await evaluate(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||
assert.ok(offer.startsWith(CODE_PREFIX));
|
||||
await input(receiver, '#offer-input', 'invalid-code!');
|
||||
@@ -564,62 +541,6 @@ try {
|
||||
await wait(sender, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
|
||||
console.log('PASS: fresh code exchange after a failed transfer succeeds without reloading either page.');
|
||||
if (!turn) {
|
||||
// Invitation links: the offer opens a dialog in a fresh page, the answer link
|
||||
// reaches the sender's tab, and other origins fall back to copy and paste.
|
||||
const inviter = await page();
|
||||
await evaluate(inviter, () => window.__hellcon.chooseFile(3000, 'invited.bin'));
|
||||
await input(inviter, '#stun-provider', provider);
|
||||
await click(inviter, 'Create code'); await wait(inviter, () => !!document.querySelector('#output-link'));
|
||||
const offerLink = await evaluate(inviter, () => window.__hellcon.element<HTMLInputElement>('#output-link').value);
|
||||
const offerCode = await evaluate(inviter, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||
assert.equal(offerLink, `${origin}/#${offerCode}`);
|
||||
const invited = await page(offerLink);
|
||||
await wait(invited, () => document.querySelector('dialog[open]')?.textContent?.includes('Invitation to receive files'));
|
||||
assert.equal(await evaluate(invited, () => location.href), `${origin}/`);
|
||||
assert.match(await dialogText(invited), /temporary identity/);
|
||||
await checkAccessibility(invited, 'Invitation dialog');
|
||||
if (screenshotDirectory) await evaluate(inviter, () => window.__hellcon.element('#output-link').scrollIntoView({ block: 'center' }));
|
||||
await screenshot(inviter, 'invitation-share');
|
||||
await screenshot(invited, 'invitation-offer');
|
||||
await call('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: false }, invited);
|
||||
assert.equal(await evaluate(invited, () => document.documentElement.scrollWidth <= innerWidth), true, 'Invitation dialog must not overflow horizontally');
|
||||
await screenshot(invited, 'invitation-offer-mobile');
|
||||
await click(invited, 'Open'); await wait(invited, () => !document.querySelector('dialog[open]'));
|
||||
await wait(invited, () => document.activeElement?.textContent === 'Accept & create answer');
|
||||
assert.equal(await evaluate(invited, () => window.__hellcon.element<HTMLTextAreaElement>('#offer-input').value), offerCode);
|
||||
assert.equal(await evaluate(invited, () => window.__hellcon.element('.tabs button[aria-pressed=true]').textContent), 'Receive');
|
||||
await input(invited, '#stun-provider', provider);
|
||||
await click(invited, 'Accept & create answer'); await wait(invited, () => !!document.querySelector('#output-link'));
|
||||
const answerLink = await evaluate(invited, () => window.__hellcon.element<HTMLInputElement>('#output-link').value);
|
||||
const answerCode = await evaluate(invited, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||
const elsewhere = await page(answerLink.replace('127.0.0.1', 'localhost'));
|
||||
await wait(elsewhere, () => document.querySelector('dialog[open]')?.textContent?.includes('Paste this answer in the sender’s tab'));
|
||||
assert.equal(await evaluate(elsewhere, () => window.__hellcon.element<HTMLTextAreaElement>('#invitation-answer').value), answerCode);
|
||||
await checkAccessibility(elsewhere, 'Answer fallback dialog');
|
||||
await screenshot(elsewhere, 'invitation-answer-fallback');
|
||||
assert.equal(await evaluate(inviter, () => !!document.querySelector('.fingerprint')), false);
|
||||
const relay = await page(answerLink);
|
||||
await wait(relay, () => document.querySelector('dialog[open]')?.textContent?.includes('Answer delivered'));
|
||||
await wait(inviter, () => !!document.querySelector('.fingerprint'));
|
||||
await evaluate(relay, (link: string) => { location.hash = link.split('#')[1]!; }, answerLink);
|
||||
await wait(relay, () => document.querySelector('dialog[open]')?.textContent?.includes('Answer already used'));
|
||||
assert.equal(await evaluate(relay, () => location.hash), '');
|
||||
await click(relay, 'Close');
|
||||
await evaluate(relay, () => { location.hash = 'HC1.not-a-code'; });
|
||||
await wait(relay, () => document.querySelector('dialog[open]')?.textContent?.includes('Link could not be opened'));
|
||||
await click(inviter, 'Both fingerprints match — confirm'); await click(invited, 'Both fingerprints match — confirm');
|
||||
await wait(invited, () => !!document.querySelector('.incoming'));
|
||||
await click(invited, 'Accept file');
|
||||
await wait(inviter, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
|
||||
const invitedBytes = await evaluate(invited, async () => {
|
||||
const link = window.__hellcon.element<HTMLAnchorElement>('a.download');
|
||||
const bytes = new Uint8Array(await (await fetch(link.href)).arrayBuffer());
|
||||
return { name: link.download, length: bytes.length, valid: bytes.every(byte => byte === 123) };
|
||||
});
|
||||
assert.deepEqual(invitedBytes, { name: 'invited.bin', length: 3000, valid: true });
|
||||
for (const session of [inviter, invited, elsewhere, relay]) await closePage(session);
|
||||
console.log('PASS: offer links open a reviewed import with a clean URL; answer links connect the waiting tab once, fall back to copy and paste elsewhere, and transfer exact bytes.');
|
||||
|
||||
const identitySender = await page();
|
||||
const receiverOrigin = origin.replace('127.0.0.1', 'localhost');
|
||||
const identityReceiver = await page(receiverOrigin);
|
||||
@@ -665,24 +586,6 @@ try {
|
||||
await click(identitySender, 'Create code'); await wait(identitySender, () => !!document.querySelector('#output-code'));
|
||||
const offer = await evaluate(identitySender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||
assert.ok((await decodeCode(offer)).identity);
|
||||
// Another receiver tab whose current slot is a new one: the invitation still
|
||||
// suggests the slot paired with the sender's device, and Open hands it there.
|
||||
const invitedPaired = await page(receiverOrigin);
|
||||
await click(invitedPaired, 'Add connection');
|
||||
await wait(invitedPaired, () => document.querySelector('.main-pane h1')?.textContent === 'Con 2');
|
||||
await evaluate(invitedPaired, (code: string) => { location.hash = code; }, offer);
|
||||
await wait(invitedPaired, () => document.querySelector('dialog[open]')?.textContent?.includes('Invitation to receive files'));
|
||||
assert.match(await dialogText(invitedPaired), /matches the paired device of Con 1/);
|
||||
assert.equal(await evaluate(invitedPaired, () => window.__hellcon.element<HTMLSelectElement>('#invitation-target').selectedOptions[0]?.textContent?.trim()), 'Con 1 · paired device');
|
||||
await click(invitedPaired, 'Open'); await wait(invitedPaired, () => !document.querySelector('dialog[open]'));
|
||||
assert.equal(await evaluate(invitedPaired, () => document.querySelector('.main-pane h1')?.textContent), 'Con 1');
|
||||
assert.equal(await evaluate(invitedPaired, () => window.__hellcon.element<HTMLTextAreaElement>('#offer-input').value), offer);
|
||||
await evaluate(invitedPaired, () => [...document.querySelectorAll<HTMLElement>('.connection-name')].find(item => item.textContent === 'Con 2')?.click());
|
||||
await wait(invitedPaired, () => document.querySelector('.main-pane h1')?.textContent === 'Con 2');
|
||||
await click(invitedPaired, 'Remove Con 2'); await click(invitedPaired, 'Remove connection');
|
||||
await wait(invitedPaired, () => document.querySelectorAll('.connection-link').length === 1);
|
||||
await closePage(invitedPaired);
|
||||
console.log('PASS: an invitation from a paired device suggests its slot over the current one and hands the code to it.');
|
||||
await input(identityReceiver, '#offer-input', offer); await click(identityReceiver, 'Accept & create answer');
|
||||
await wait(identityReceiver, () => !!document.querySelector('#output-code'));
|
||||
const answer = await evaluate(identityReceiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||
|
||||
Reference in new issue
Block a user