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",
|
||||
"private": true,
|
||||
"version": "0.1.0-b.2",
|
||||
"version": "0.1.0-b3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "wxt",
|
||||
|
||||
@@ -7,12 +7,12 @@ export function handlePageControlMessage(
|
||||
message: { type: 'PAGE_CONTROL'; action: string; payload: any; targetTabId: number },
|
||||
sender: chrome.runtime.MessageSender,
|
||||
sendResponse: (response: unknown) => void
|
||||
): boolean {
|
||||
): true | undefined {
|
||||
const { action, payload, targetTabId } = message
|
||||
|
||||
if (action === 'get_my_tab_id') {
|
||||
sendResponse({ tabId: sender.tab?.id || null })
|
||||
return false
|
||||
return
|
||||
}
|
||||
|
||||
chrome.tabs
|
||||
|
||||
@@ -53,12 +53,12 @@ export function initPageController() {
|
||||
}
|
||||
}, 1_000)
|
||||
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse): true | undefined => {
|
||||
if (message.type !== 'PAGE_CONTROL') {
|
||||
sendResponse({
|
||||
success: false,
|
||||
error: `[RemotePageController.ContentScript]: Invalid message type: ${message.type}`,
|
||||
})
|
||||
// sendResponse({
|
||||
// success: false,
|
||||
// error: `[RemotePageController.ContentScript]: Invalid message type: ${message.type}`,
|
||||
// })
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ export function handleTabControlMessage(
|
||||
message: { type: 'TAB_CONTROL'; action: TabAction; payload: any },
|
||||
sender: chrome.runtime.MessageSender,
|
||||
sendResponse: (response: unknown) => void
|
||||
): boolean {
|
||||
): true | undefined {
|
||||
const { action, payload } = message
|
||||
|
||||
switch (action as TabAction) {
|
||||
@@ -102,6 +102,6 @@ export function handleTabControlMessage(
|
||||
|
||||
default:
|
||||
sendResponse({ error: `Unknown action: ${action}` })
|
||||
return false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,11 @@ export class TabsController extends EventTarget {
|
||||
|
||||
await this.updateCurrentTabId(this.currentTabId)
|
||||
|
||||
const tabChangeHandler = (message: any) => {
|
||||
if (message.type !== 'TAB_CHANGE')
|
||||
throw new Error(`[TabsController]: Invalid message type: ${message.type}`)
|
||||
const tabChangeHandler = (message: any): void => {
|
||||
if (message.type !== 'TAB_CHANGE') {
|
||||
// throw new Error(`[TabsController]: Invalid message type: ${message.type}`)
|
||||
return
|
||||
}
|
||||
|
||||
if (message.action === 'created') {
|
||||
const tab = message.payload.tab as chrome.tabs.Tab
|
||||
|
||||
@@ -249,10 +249,10 @@ function StepCard({ event }: { event: AgentStepEvent }) {
|
||||
)}
|
||||
</p>
|
||||
<p className="text-[11px] text-muted-foreground/70 grid grid-cols-[auto_1fr] gap-1.5">
|
||||
<div className="">└</div>
|
||||
<div className="wrap-anywhere break-all line-clamp-1 hover:line-clamp-3">
|
||||
<span className="">└</span>
|
||||
<span className="wrap-anywhere break-all line-clamp-1 hover:line-clamp-3">
|
||||
{event.action.output}
|
||||
</div>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user