Keep the frames of pasted GIF, WebP, and AVIF images
A browser puts only the first frame of an image on the clipboard, with HTML that names the image address. - Documents and cards download the original of a GIF, WebP, or AVIF address. The host commands workspace_save_image_url and workspace_download_image read the format from the file contents and refuse other data. A failed download keeps the first frame and shows a message. - Copy image in the RuneStone browser keeps the bytes that the page loaded. The engine reads them through the DevTools Protocol, so the website gets no second request. The new copiedImage command gives them in parts below the line limit of the host. A paste uses them first. - An empty dropped image file shows a message. Firefox gives such a file when the website refuses its download. Copy image needs a new browser engine build. Card 0d5c18f7.
This commit is contained in:
@@ -124,6 +124,56 @@ app.whenReady().then(async () => {
|
||||
await assert.rejects(engine.command('contextAction', { tabId: first, token: 'expired', action: 'saveImage' }), /no longer available/);
|
||||
await wc.executeJavaScript('document.querySelector("#save-image").remove();true;');
|
||||
passed.push('Unicode text, native image context menus, saved image bytes and stale menu protection work');
|
||||
// Copy image keeps the bytes that the page loaded. The test server gives this GIF only one time.
|
||||
await wc.executeJavaScript(`document.body.insertAdjacentHTML('beforeend', '<img id="copy-image" src="${process.env.RS_TEST_URL}once.gif" style="position:absolute;left:400px;top:40px;width:80px;height:80px">');true;`);
|
||||
await until(async () => await wc.executeJavaScript('document.querySelector("#copy-image").complete'));
|
||||
const menus = events.length;
|
||||
await engine.command('input', { tabId: first, input: { type: 'mouseDown', x: 440, y: 80, button: 'right' } });
|
||||
await engine.command('input', { tabId: first, input: { type: 'mouseUp', x: 440, y: 80, button: 'right' } });
|
||||
await until(() => events.slice(menus).some(event => event.event === 'context-menu' && event.hasImageContents));
|
||||
const imageMenu = events.findLast(event => event.event === 'context-menu');
|
||||
const { copied } = await engine.command('contextAction', { tabId: first, token: imageMenu.token, action: 'copyImage' });
|
||||
assert.deepEqual([copied.url, copied.mime, copied.size], [`${process.env.RS_TEST_URL}once.gif`, 'image/gif', 85]);
|
||||
const part = await engine.command('copiedImage', { tabId: first, token: copied.token, offset: 0 });
|
||||
const bytes = Buffer.from(part.data, 'base64');
|
||||
assert.equal(bytes.subarray(0, 6).toString(), 'GIF89a');
|
||||
assert.equal(bytes.length, 85);
|
||||
assert.equal(part.next, null);
|
||||
await assert.rejects(engine.command('copiedImage', { tabId: first, token: copied.token, offset: 85 }), /no longer available/);
|
||||
await assert.rejects(engine.command('copiedImage', { tabId: 'other', token: copied.token, offset: 0 }), /no longer available/);
|
||||
// A large image comes in parts that stay below the line limit of the host.
|
||||
await wc.executeJavaScript(`document.querySelector("#copy-image").src = "${process.env.RS_TEST_URL}large.gif";true;`);
|
||||
await until(async () => await wc.executeJavaScript('document.querySelector("#copy-image").complete && document.querySelector("#copy-image").naturalWidth === 1'));
|
||||
const largeMenus = events.length;
|
||||
await engine.command('input', { tabId: first, input: { type: 'mouseDown', x: 440, y: 80, button: 'right' } });
|
||||
await engine.command('input', { tabId: first, input: { type: 'mouseUp', x: 440, y: 80, button: 'right' } });
|
||||
await until(() => events.slice(largeMenus).some(event => event.event === 'context-menu' && event.hasImageContents));
|
||||
const large = (await engine.command('contextAction', { tabId: first, token: events.findLast(event => event.event === 'context-menu').token, action: 'copyImage' })).copied;
|
||||
const parts = [];
|
||||
for (let offset = 0; offset !== null;) {
|
||||
const next = await engine.command('copiedImage', { tabId: first, token: large.token, offset });
|
||||
assert.ok(next.data.length <= 4_000_000);
|
||||
parts.push(Buffer.from(next.data, 'base64')); offset = next.next;
|
||||
}
|
||||
const whole = Buffer.concat(parts);
|
||||
assert.ok(parts.length >= 3);
|
||||
assert.equal(whole.length, large.size);
|
||||
assert.equal(whole.subarray(0, 6).toString(), 'GIF89a');
|
||||
assert.equal(whole.at(-1), 0x3b);
|
||||
await wc.executeJavaScript('document.querySelector("#copy-image").remove();true;');
|
||||
// An image that opens as the page itself is the main resource of the tab.
|
||||
const direct = (await engine.command('newTab', { url: `${process.env.RS_TEST_URL}direct.gif` })).tabId;
|
||||
const directContents = engine.tabs.get(direct).view.webContents;
|
||||
await until(async () => await directContents.executeJavaScript('document.images[0]?.complete === true').catch(() => false));
|
||||
const box = await directContents.executeJavaScript('(({ x, y, width, height }) => ({ x: Math.floor(x + width / 2), y: Math.floor(y + height / 2) }))(document.images[0].getBoundingClientRect())');
|
||||
const directMenus = events.length;
|
||||
await engine.command('input', { tabId: direct, input: { type: 'mouseDown', ...box, button: 'right' } });
|
||||
await engine.command('input', { tabId: direct, input: { type: 'mouseUp', ...box, button: 'right' } });
|
||||
await until(() => events.slice(directMenus).some(event => event.event === 'context-menu' && event.tabId === direct && event.hasImageContents));
|
||||
const directCopy = (await engine.command('contextAction', { tabId: direct, token: events.findLast(event => event.event === 'context-menu').token, action: 'copyImage' })).copied;
|
||||
assert.deepEqual([directCopy.mime, directCopy.size], ['image/gif', large.size]);
|
||||
await engine.command('closeTab', { tabId: direct });
|
||||
passed.push('Copy image keeps the loaded GIF bytes without a second request, also for an image that opens as the page');
|
||||
await until(async () => await wc.executeJavaScript("getComputedStyle(document.querySelector('.advertisement')).display") === 'none');
|
||||
assert.equal(await wc.executeJavaScript('typeof window.adExecuted'), 'undefined');
|
||||
passed.push('network and cosmetic ad blocking remain active');
|
||||
|
||||
Reference in New Issue
Block a user