Add shareable invitation links
Codes now travel as links with the code in the URL fragment, which the app reads and clears before mounting (and on hashchange). An offer link opens a preview that suggests an idle slot, preferring the one paired with the sender's device, and only fills in the code; the user still creates the answer. Answer links reach the waiting sender tab over a same-origin BroadcastChannel, are acknowledged once and reported as used afterwards, and fall back to copy and paste when no tab answers. The panel offers Share link where the Web Share API accepts URLs, Copy link, and the bare code under a disclosure. The browser check covers the offer dialog, clean URL, answer relay, reuse, fallback on another origin, an invalid fragment, axe on both dialogs and exact bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8bd37ac8b1
commit
43ee7f119f
14 files changed
+422
-59
No files matched your search
@@ -49,6 +49,7 @@ 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;
|
||||
@@ -99,9 +100,11 @@ 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.
|
||||
@@ -114,7 +117,8 @@ 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++) {
|
||||
try { if (await evaluate(sessionId, (expected: string) => location.href.startsWith(expected) && document.readyState === 'complete', url)) break; }
|
||||
// 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; }
|
||||
catch (err) { if (!(err instanceof Error) || !err.message.includes('context')) throw err; }
|
||||
await new Promise(resolve => setTimeout(resolve, 20));
|
||||
}
|
||||
@@ -132,6 +136,15 @@ async function checkAccessibility(session: string, mode: string) {
|
||||
});
|
||||
assert.deepEqual(violations, [], `${mode} mode accessibility violations`);
|
||||
}
|
||||
const screenshot = async (session: string, name: string) => {
|
||||
if (!screenshotDirectory) return;
|
||||
await mkdir(screenshotDirectory, { recursive: true });
|
||||
await call('Page.bringToFront', {}, session);
|
||||
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);
|
||||
const enableTurn = (session: string) => evaluate(session, () => {
|
||||
@@ -212,13 +225,6 @@ try {
|
||||
if (!button) throw new Error('Missing connection: ' + name);
|
||||
button.click();
|
||||
}, name);
|
||||
const screenshot = async (session: string, name: string) => {
|
||||
if (!screenshotDirectory) return;
|
||||
await mkdir(screenshotDirectory, { recursive: true });
|
||||
await call('Page.bringToFront', {}, session);
|
||||
const { data } = await call('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false }, session);
|
||||
await writeFile(join(screenshotDirectory, name + '.png'), Buffer.from(data, 'base64'));
|
||||
};
|
||||
await call('Emulation.setDeviceMetricsOverride', { width: 1440, height: 1000, deviceScaleFactor: 1, mobile: false }, sender);
|
||||
assert.equal(await evaluate(sender, () => document.querySelector('.title-line h1')?.textContent), 'Con 1');
|
||||
await checkAccessibility(sender, 'Connections desktop');
|
||||
@@ -475,6 +481,62 @@ 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);
|
||||
|
||||
Reference in new issue
Block a user