askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
site icons (favicons) in tabs, address bar suggestions and the bookmarks panel
7249579
15 hours, 56 minutes ago
History
ext-echo.mjs · 1.6 KB · 31 lines
| 1 | // A tiny extension for the tests. It also pins the parts of the browser that local extensions are allowed to rely on: |
| 2 | // the page of a tab, the window that hosts it, and that asking for a page never raises or focuses the window. |
| 3 | import { BrowserWindow } from "electron"; |
| 4 | |
| 5 | export function register(api) { |
| 6 | api.method("echo", async (params, tools) => { |
| 7 | const wc = await tools.webContents(params); |
| 8 | return { url: wc.getURL(), said: params.say ?? null }; |
| 9 | }); |
| 10 | api.method("boom", () => { |
| 11 | throw new Error("boom on purpose"); |
| 12 | }); |
| 13 | // The window that hosts a page, found the way an extension would find it. |
| 14 | api.method("host", async (params, tools) => { |
| 15 | const wc = await tools.webContents(params); |
| 16 | const win = wc.hostWebContents ? BrowserWindow.fromWebContents(wc.hostWebContents) : null; |
| 17 | return { found: !!win, contentSize: win ? win.getContentSize() : null, type: wc.getType() }; |
| 18 | }); |
| 19 | // The window's state, to compare before and after other calls. |
| 20 | api.method("window", () => { |
| 21 | const win = BrowserWindow.getAllWindows()[0]; |
| 22 | return { focused: win.isFocused(), visible: win.isVisible(), minimized: win.isMinimized(), size: win.getContentSize(), position: win.getPosition() }; |
| 23 | }); |
| 24 | // Can the page be painted into an image (the same call page.screenshot uses)? Never waits for ever. |
| 25 | api.method("paintable", async (params, tools) => { |
| 26 | const wc = await tools.webContents(params); |
| 27 | const img = await Promise.race([wc.capturePage(), new Promise((_, no) => setTimeout(() => no(new Error("not painted within 8 s")), 8000))]); |
| 28 | const s = img.getSize(); |
| 29 | return { width: s.width, height: s.height, empty: img.isEmpty() }; |
| 30 | }); |
| 31 | } |