experiments in a post-browser web
10
fork

Configure Feed

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

fix(tests): improve extension ID detection and shared instance handling

+51 -17
+3 -4
tests/extension/options.spec.ts
··· 6 6 */ 7 7 8 8 import { test, expect } from '@playwright/test'; 9 - import { getSharedExtension, closeSharedExtension, ExtensionApp } from '../fixtures/extension-app'; 9 + import { getSharedExtension, ExtensionApp } from '../fixtures/extension-app'; 10 10 import { 11 11 waitForOptionsInit, 12 12 fillSyncConfig, ··· 31 31 ext = await getSharedExtension(); 32 32 }); 33 33 34 - test.afterAll(async () => { 35 - await closeSharedExtension(); 36 - }); 34 + // Don't close shared extension - let Playwright handle cleanup 35 + // This allows multiple test files to share the same browser instance 37 36 38 37 test.beforeEach(async () => { 39 38 // Open a fresh options page for each test
+3 -4
tests/extension/popup.spec.ts
··· 6 6 */ 7 7 8 8 import { test, expect } from '@playwright/test'; 9 - import { getSharedExtension, closeSharedExtension, ExtensionApp } from '../fixtures/extension-app'; 9 + import { getSharedExtension, ExtensionApp } from '../fixtures/extension-app'; 10 10 import { 11 11 waitForCommandInput, 12 12 typeCommand, ··· 26 26 ext = await getSharedExtension(); 27 27 }); 28 28 29 - test.afterAll(async () => { 30 - await closeSharedExtension(); 31 - }); 29 + // Don't close shared extension - let Playwright handle cleanup 30 + // This allows multiple test files to share the same browser instance 32 31 33 32 test.beforeEach(async () => { 34 33 // Open a fresh popup for each test
+45 -9
tests/fixtures/extension-app.ts
··· 85 85 ], 86 86 }); 87 87 88 - // Wait for the service worker to be registered and get the extension ID 88 + // Wait for the service worker to be registered 89 89 let extensionId = ''; 90 - const maxWait = 10000; 91 - const start = Date.now(); 90 + 91 + // Method 1: Wait for service worker event with timeout 92 + try { 93 + const workerPromise = context.waitForEvent('serviceworker', { timeout: 10000 }); 94 + const worker = await workerPromise; 95 + const url = worker.url(); 96 + if (url.startsWith('chrome-extension://')) { 97 + const match = url.match(/chrome-extension:\/\/([^/]+)/); 98 + if (match) { 99 + extensionId = match[1]; 100 + } 101 + } 102 + } catch { 103 + // Timeout - try alternative methods 104 + } 92 105 93 - while (Date.now() - start < maxWait) { 94 - // Check service workers for the extension 106 + // Method 2: Check existing service workers 107 + if (!extensionId) { 95 108 const workers = context.serviceWorkers(); 96 109 for (const worker of workers) { 97 110 const url = worker.url(); 98 - if (url.startsWith('chrome-extension://') && url.includes('background.js')) { 99 - // Extract extension ID from URL: chrome-extension://{id}/background.js 111 + if (url.startsWith('chrome-extension://')) { 100 112 const match = url.match(/chrome-extension:\/\/([^/]+)/); 101 113 if (match) { 102 114 extensionId = match[1]; ··· 104 116 } 105 117 } 106 118 } 107 - if (extensionId) break; 108 - await sleep(100); 119 + } 120 + 121 + // Method 3: Open a blank page and use chrome.runtime to get extension ID 122 + if (!extensionId) { 123 + // Open default page (about:blank) and list all service workers via devtools 124 + const page = context.pages()[0] || await context.newPage(); 125 + 126 + // Poll for service workers 127 + const maxWait = 10000; 128 + const start = Date.now(); 129 + while (Date.now() - start < maxWait && !extensionId) { 130 + const workers = context.serviceWorkers(); 131 + for (const worker of workers) { 132 + const url = worker.url(); 133 + if (url.startsWith('chrome-extension://')) { 134 + const match = url.match(/chrome-extension:\/\/([^/]+)/); 135 + if (match) { 136 + extensionId = match[1]; 137 + break; 138 + } 139 + } 140 + } 141 + if (!extensionId) { 142 + await sleep(200); 143 + } 144 + } 109 145 } 110 146 111 147 if (!extensionId) {