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:
@@ -52,9 +52,19 @@ async function startEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
// A two-frame GIF that the fixture gives only one time, as some image hosts do.
|
||||
const onceGif = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQACgAAACwAAAAAAQABAAACAkQBACH5BAAKAAAALAAAAAABAAEAAAICTAEAOw==', 'base64');
|
||||
|
||||
/** Serve an empty page. A tab on about:blank shows the host background instead of frames (docs/ui-design.md:218). */
|
||||
async function startFixture() {
|
||||
const server = createServer((_request, response) => { response.writeHead(200, { 'content-type': 'text/html' }); response.end('<!doctype html><title>Fixture</title><body></body>'); });
|
||||
let gifServed = false;
|
||||
const server = createServer((request, response) => {
|
||||
if (request.url === '/once.gif') {
|
||||
response.writeHead(200, { 'content-type': gifServed ? 'text/html' : 'image/gif' });
|
||||
response.end(gifServed ? 'Invalid request' : onceGif); gifServed = true; return;
|
||||
}
|
||||
response.writeHead(200, { 'content-type': 'text/html' }); response.end('<!doctype html><title>Fixture</title><body></body>');
|
||||
});
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
return { url: `http://127.0.0.1:${server.address().port}/`, close: () => new Promise(resolve => server.close(resolve)) };
|
||||
}
|
||||
@@ -120,6 +130,15 @@ await runSmoke('browser/interaction', async ({ browser }) => {
|
||||
await page.mouse.click(initialBox.x + 100, initialBox.y + 60);
|
||||
await page.keyboard.press('Control+a'); await page.keyboard.press('Control+v');
|
||||
await expectRemote('document.querySelector("#typing").value', 'https://example.com/');
|
||||
// Copy image keeps the GIF bytes that the page loaded, also when the website refuses a second request.
|
||||
const gifUrl = `${fixture.url}once.gif`;
|
||||
await evaluate(`document.body.innerHTML='<img id="gif" src="${gifUrl}" style="position:absolute;left:40px;top:300px;width:80px;height:80px">';true;`);
|
||||
await expectRemote('document.querySelector("#gif").complete && document.querySelector("#gif").naturalWidth', 1);
|
||||
await page.mouse.click(initialBox.x + 80, initialBox.y + 340, { button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Copy image', exact: true }).click();
|
||||
const copied = await page.evaluate(async url => (await import('/src/lib/workspace/copiedImage.ts')).copiedImage(url), gifUrl);
|
||||
assert.equal(copied, `data:image/gif;base64,${onceGif.toString('base64')}`);
|
||||
assert.equal(commands.filter(call => call.command === 'copiedImage').length, 1);
|
||||
await evaluate(`document.body.innerHTML='<canvas width="1000" height="700"></canvas>'; const c=document.querySelector('canvas').getContext('2d'); let n=0; window.testAnimate=true; function draw(){ c.fillStyle='#fff';c.fillRect(0,0,1000,700);c.fillStyle='#5482ff';c.fillRect(n++*5%900,200,80,80);if(window.testAnimate)requestAnimationFrame(draw); } draw();true;`);
|
||||
await page.locator('.surface img').waitFor();
|
||||
await page.evaluate(() => { window.decodedFrames = 0; document.querySelector('.surface img').addEventListener('load', () => window.decodedFrames++); });
|
||||
|
||||
Reference in New Issue
Block a user