fix(ext): fix multi-thread logic; extensive logging and error handling
This commit is contained in:
@@ -8,13 +8,21 @@ export function handlePageControlMessage(
|
||||
sender: chrome.runtime.MessageSender,
|
||||
sendResponse: (response: unknown) => void
|
||||
): true | undefined {
|
||||
const PREFIX = '[RemotePageController.background]'
|
||||
|
||||
function debug(...messages: any[]) {
|
||||
console.debug(`\x1b[90m${PREFIX}\x1b[0m`, ...messages)
|
||||
}
|
||||
|
||||
const { action, payload, targetTabId } = message
|
||||
|
||||
if (action === 'get_my_tab_id') {
|
||||
debug('get_my_tab_id', sender.tab?.id)
|
||||
sendResponse({ tabId: sender.tab?.id || null })
|
||||
return
|
||||
}
|
||||
|
||||
// proxy to content script
|
||||
chrome.tabs
|
||||
.sendMessage(targetTabId, {
|
||||
type: 'PAGE_CONTROL',
|
||||
@@ -25,6 +33,7 @@ export function handlePageControlMessage(
|
||||
sendResponse(result)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(PREFIX, error)
|
||||
sendResponse({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
|
||||
Reference in New Issue
Block a user