import { webExtApi as api } from '../browser-api'; import type { ScriptInjection, ScriptInjectionResult } from '../types'; // api.scripting.executeScript wrapper with transient-error retry. import { isTransientScriptError } from './errors'; import { sleep } from './throttle'; import type { Serializable } from '../types'; export async function executeScript( options: ScriptInjection, retries = 3, ): Promise[]> { for (let i = 0; i < retries; i++) { try { return await api.scripting.executeScript(options); } catch (e) { if (i < retries - 1 && isTransientScriptError(e)) { await sleep(300); continue; } throw e; } } // Unreachable: the loop either returns or throws on the final iteration. throw new Error("executeScript: exhausted retries"); }