0

This question is about the Firefox API function:

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/sendMessage

Why does browser.tabs.sendMessage() not seem to return a specific error that causes the rejection of the Promise as a reason? Instead, the function appears to return a generic Error and the same message that a specific Error would have.

Is this due to the implementation of sendMessage()? Does it use the generic Error type, because it must be able to return all types of Errors?


I know that https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject says that:

The static Promise.reject function returns a Promise that is rejected. For debugging purposes and selective error catching, it is useful to make reason an instanceof Error.


I would expect to know the specific Error, because if it is just an Error, then I am not sure if it is always easy to understand what causes it.

14
  • Do you have some code to reproduce? What are you trying to figure out about the error you're getting? Commented Apr 13 at 13:50
  • @guest271314 The page above gives an example: developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/…. There you can further rewrite the line with browser.tabs.sendMessage() so that it looks more like: var atab = browser.tabs; var result = atab.sendMessage(...);. Then inspect what you see in result if you cause an error inside content.js. Commented Apr 13 at 13:52
  • What are you trying to determine? Commented Apr 13 at 13:57
  • @guest271314 It could be nice to branch in the background script in different cases of Errors. Possibly, the code used here implies that one should do the branching in the content script. Commented Apr 13 at 13:58
  • You should be able to. I don't see what's stopping you from doing that. Commented Apr 13 at 13:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.