fix(ext): update message handlers
> If multiple listeners are registered for onMessage, > only the first listener to respond, reject, or throw > an error will affect the sender; all other listeners > will run, but their results will be ignored.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@page-agent/ext",
|
"name": "@page-agent/ext",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0-b.2",
|
"version": "0.1.0-b3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "wxt",
|
"dev": "wxt",
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ export function handlePageControlMessage(
|
|||||||
message: { type: 'PAGE_CONTROL'; action: string; payload: any; targetTabId: number },
|
message: { type: 'PAGE_CONTROL'; action: string; payload: any; targetTabId: number },
|
||||||
sender: chrome.runtime.MessageSender,
|
sender: chrome.runtime.MessageSender,
|
||||||
sendResponse: (response: unknown) => void
|
sendResponse: (response: unknown) => void
|
||||||
): boolean {
|
): true | undefined {
|
||||||
const { action, payload, targetTabId } = message
|
const { action, payload, targetTabId } = message
|
||||||
|
|
||||||
if (action === 'get_my_tab_id') {
|
if (action === 'get_my_tab_id') {
|
||||||
sendResponse({ tabId: sender.tab?.id || null })
|
sendResponse({ tabId: sender.tab?.id || null })
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs
|
chrome.tabs
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ export function initPageController() {
|
|||||||
}
|
}
|
||||||
}, 1_000)
|
}, 1_000)
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse): true | undefined => {
|
||||||
if (message.type !== 'PAGE_CONTROL') {
|
if (message.type !== 'PAGE_CONTROL') {
|
||||||
sendResponse({
|
// sendResponse({
|
||||||
success: false,
|
// success: false,
|
||||||
error: `[RemotePageController.ContentScript]: Invalid message type: ${message.type}`,
|
// error: `[RemotePageController.ContentScript]: Invalid message type: ${message.type}`,
|
||||||
})
|
// })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export function handleTabControlMessage(
|
|||||||
message: { type: 'TAB_CONTROL'; action: TabAction; payload: any },
|
message: { type: 'TAB_CONTROL'; action: TabAction; payload: any },
|
||||||
sender: chrome.runtime.MessageSender,
|
sender: chrome.runtime.MessageSender,
|
||||||
sendResponse: (response: unknown) => void
|
sendResponse: (response: unknown) => void
|
||||||
): boolean {
|
): true | undefined {
|
||||||
const { action, payload } = message
|
const { action, payload } = message
|
||||||
|
|
||||||
switch (action as TabAction) {
|
switch (action as TabAction) {
|
||||||
@@ -102,6 +102,6 @@ export function handleTabControlMessage(
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
sendResponse({ error: `Unknown action: ${action}` })
|
sendResponse({ error: `Unknown action: ${action}` })
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,11 @@ export class TabsController extends EventTarget {
|
|||||||
|
|
||||||
await this.updateCurrentTabId(this.currentTabId)
|
await this.updateCurrentTabId(this.currentTabId)
|
||||||
|
|
||||||
const tabChangeHandler = (message: any) => {
|
const tabChangeHandler = (message: any): void => {
|
||||||
if (message.type !== 'TAB_CHANGE')
|
if (message.type !== 'TAB_CHANGE') {
|
||||||
throw new Error(`[TabsController]: Invalid message type: ${message.type}`)
|
// throw new Error(`[TabsController]: Invalid message type: ${message.type}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (message.action === 'created') {
|
if (message.action === 'created') {
|
||||||
const tab = message.payload.tab as chrome.tabs.Tab
|
const tab = message.payload.tab as chrome.tabs.Tab
|
||||||
|
|||||||
@@ -249,10 +249,10 @@ function StepCard({ event }: { event: AgentStepEvent }) {
|
|||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-[11px] text-muted-foreground/70 grid grid-cols-[auto_1fr] gap-1.5">
|
<p className="text-[11px] text-muted-foreground/70 grid grid-cols-[auto_1fr] gap-1.5">
|
||||||
<div className="">└</div>
|
<span className="">└</span>
|
||||||
<div className="wrap-anywhere break-all line-clamp-1 hover:line-clamp-3">
|
<span className="wrap-anywhere break-all line-clamp-1 hover:line-clamp-3">
|
||||||
{event.action.output}
|
{event.action.output}
|
||||||
</div>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user