fix(extension): resolve race condition in hub config and fix tab initialization crash
add: erp scrape python demo
This commit is contained in:
@@ -47,7 +47,7 @@ export class RemotePageController {
|
||||
}
|
||||
|
||||
async getLastUpdateTime(): Promise<number> {
|
||||
if (!this.currentTabId) throw new Error('tabsController not initialized.')
|
||||
if (!this.currentTabId) return Date.now()
|
||||
return sendMessage({
|
||||
type: 'PAGE_CONTROL',
|
||||
action: 'get_last_update_time',
|
||||
|
||||
@@ -218,9 +218,23 @@ export function useHubWs(
|
||||
Number(wsPort),
|
||||
{
|
||||
onExecute: async (task, incomingConfig) => {
|
||||
const { execute, configure, config } = latestRef.current
|
||||
let { execute } = latestRef.current
|
||||
const { configure, config } = latestRef.current
|
||||
if (incomingConfig) {
|
||||
await configure({ ...config, ...incomingConfig } as ExtConfig)
|
||||
let changed = false
|
||||
for (const key of Object.keys(incomingConfig)) {
|
||||
if (incomingConfig[key] !== (config as any)?.[key]) {
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
await configure({ ...config, ...incomingConfig } as ExtConfig)
|
||||
// Wait a bit for React to re-render and instantiate the new MultiPageAgent
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
// Re-fetch the newly generated execute function after re-render
|
||||
execute = latestRef.current.execute
|
||||
}
|
||||
}
|
||||
const result = await execute(task)
|
||||
return { success: result.success, data: result.data }
|
||||
|
||||
Reference in New Issue
Block a user