Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(messaging): More explicit error message when no active tabs #797

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/messaging/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export const sendToBackground: PlasmoMessaging.SendFx<MessageName> = async (
*/
export const sendToContentScript: PlasmoMessaging.SendFx = async (req) => {
const tabId =
typeof req.tabId === "number" ? req.tabId : (await getActiveTab()).id
typeof req.tabId === "number" ? req.tabId : (await getActiveTab())?.id

if (!tabId) {
throw new Error("No active tab found to send message to.")
}

return getExtTabs().sendMessage(tabId, req)
}
Expand Down
2 changes: 1 addition & 1 deletion api/messaging/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getActiveTab = async () => {
active: true,
currentWindow: true
})
return tab
return tab as chrome.tabs.Tab | undefined
}

export const isSameOrigin = (
Expand Down