Skip to content

Commit dac6c63

Browse files
committed
working extension tests
1 parent 42d3fb7 commit dac6c63

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

archivebox/plugins/chrome/on_Crawl__30_chrome_launch.bg.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,25 @@ async function main() {
215215
const manifestPath = path.join(ext.unpacked_path, 'manifest.json');
216216
if (fs.existsSync(manifestPath)) {
217217
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
218-
const manifestName = manifest.name || '';
218+
let manifestName = manifest.name || '';
219+
220+
// Resolve message placeholder (e.g., __MSG_extName__)
221+
if (manifestName.startsWith('__MSG_') && manifestName.endsWith('__')) {
222+
const msgKey = manifestName.slice(6, -2); // Extract key from __MSG_key__
223+
const defaultLocale = manifest.default_locale || 'en';
224+
const messagesPath = path.join(ext.unpacked_path, '_locales', defaultLocale, 'messages.json');
225+
if (fs.existsSync(messagesPath)) {
226+
try {
227+
const messages = JSON.parse(fs.readFileSync(messagesPath, 'utf-8'));
228+
if (messages[msgKey] && messages[msgKey].message) {
229+
manifestName = messages[msgKey].message;
230+
}
231+
} catch (e) {
232+
console.error(`[!] Failed to read messages.json: ${e.message}`);
233+
}
234+
}
235+
}
236+
219237
console.error(`[*] Looking for match: ext.name="${ext.name}" manifest.name="${manifestName}"`);
220238

221239
// Find matching extension from page by exact name match first

archivebox/plugins/twocaptcha/tests/test_twocaptcha.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,18 @@ def launch_chrome(env: dict, chrome_dir: Path, crawl_id: str):
142142
)
143143

144144
cdp_url = None
145+
extensions_ready = False
145146
for _ in range(30):
146147
if process.poll() is not None:
147148
stdout, stderr = process.communicate()
148149
raise RuntimeError(f"Chromium failed:\n{stdout}\n{stderr}")
149150
cdp_file = chrome_dir / 'cdp_url.txt'
150-
if cdp_file.exists():
151+
ext_file = chrome_dir / 'extensions.json'
152+
if cdp_file.exists() and not cdp_url:
151153
cdp_url = cdp_file.read_text().strip()
154+
if ext_file.exists():
155+
extensions_ready = True
156+
if cdp_url and extensions_ready:
152157
break
153158
time.sleep(1)
154159

@@ -157,13 +162,6 @@ def launch_chrome(env: dict, chrome_dir: Path, crawl_id: str):
157162
stdout, stderr = process.communicate()
158163
raise RuntimeError(f"CDP URL not found after 30s.\nstdout: {stdout}\nstderr: {stderr}")
159164

160-
# Wait for extensions.json to be written (chrome launch hook parses chrome://extensions)
161-
extensions_file = chrome_dir / 'extensions.json'
162-
for _ in range(15):
163-
if extensions_file.exists():
164-
break
165-
time.sleep(1)
166-
167165
# Print chrome launch hook output for debugging
168166
import select
169167
if hasattr(select, 'poll'):

0 commit comments

Comments
 (0)