[READ-ONLY] Mirror of https://github.com/jackmawer/oembed-imagifier. Converts oEmbed-capable URLs into images
0

Configure Feed

Select the types of activity you want to include in your feed.

Clip to target element if possible

- Most oEmbeds seem to render an internal div as the first body child, so we can try to select and only screenshot that element to allow us to have a tighter screenshot

Jack (Feb 1, 2025, 2:13 PM UTC) 164d4bdd c04797c0

+20 -4
+2 -2
package.json
··· 4 4 "description": "Converts oEmbed-capable URLs into images", 5 5 "scripts": { 6 6 "deploy": "wrangler deploy", 7 - "dev": "wrangler dev", 8 - "start": "wrangler dev", 7 + "dev": "wrangler dev --remote", 8 + "start": "wrangler dev --remote", 9 9 "test": "vitest", 10 10 "cf-typegen": "wrangler types" 11 11 },
+18 -2
src/index.ts
··· 47 47 48 48 app.get('/', (c) => c.json({ message: 'Hello, World!' })); 49 49 50 + app.get('/oembed/:url{.+}', async (c) => { 51 + const url = c.req.param('url'); 52 + const oembed = await getOembed(url); 53 + 54 + if (oembed) { 55 + return c.json(oembed); 56 + } else { 57 + return c.json({ error: 'No oEmbed available.' }, 400); 58 + } 59 + }); 60 + 50 61 app.get('/png/:url{.+}', async (c) => { 51 62 // Get oEmbed data 52 63 const url = c.req.param('url'); ··· 62 73 idleTime: 1000 63 74 }); 64 75 await new Promise(r=>setTimeout(r, 1000)); 65 - let img = await page.screenshot({ 66 - fullPage: true, 76 + 77 + const target = (await page.$('body div')) || page; 78 + 79 + let img = await target.screenshot({ 80 + // If we were able to find a selector, no need to apply fullPage. 81 + // Otherwise, capture as much as possible. 82 + fullPage: target === page, 67 83 captureBeyondViewport: true 68 84 }); 69 85