bbiz Script Runner

从 Web 页面调用 Chrome 扩展,在目标页面执行 JS 脚本并获取返回值

配置

调用

选择后会自动填充示例 URL、对应脚本,并优先从脚本里提取第一个选择器作为默认就绪选择器。

执行结果


  

在你的页面中集成

// 在已加入 externally_connectable 白名单的页面中直接调用 const EXTENSION_ID = "your_extension_id_here"; async function runScript(url, script, options = {}) { return new Promise((resolve, reject) => { chrome.runtime.sendMessage(EXTENSION_ID, { action: "executeScript", url, script: script, timeout: options.timeout ?? 30000, closeTab: options.closeTab ?? true, readySelector: options.readySelector ?? "", readySelectorTimeout: options.readySelectorTimeout ?? 15000, scriptRuntimeExceptionTypes: options.scriptRuntimeExceptionTypes ?? ["login_required", "shield"], postLoadWait: options.postLoadWait, }, (response) => { if (chrome.runtime.lastError) return reject(chrome.runtime.lastError); response.success ? resolve(response.result) : reject(response.error); }); }); } // 扩展会在目标页面主环境预写入 window.__bbizPlatform__ 与 window.__bbizContext__ // 使用示例 const result = await runScript( "https://example.com", "return { platform: window.__bbizPlatform__, title: document.title, url: location.href };" ); console.log(result);