Closed Bug 1435597 Opened 8 years ago Closed 8 years ago

Callback parameter from chrome.runtime.sendMessage is undefined

Categories

(WebExtensions :: General, defect)

58 Branch
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: juraj.masiar, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0 Build ID: 20180201171410 Steps to reproduce: I'm author of GroupSpeedDial and several users every day report one error I managed to identify as this: 1) create custom add-on page with JavaScript requesting some data from background script using code: chrome.runtime.sendMessage({type: 'getImages'}, data => { if (!data) throw Error('this is impossible!') }) 2) in background script on the file top level (not nested in any function) create single listener using this code: chrome.runtime.onMessage.addListener((data, sender, sendResponse) => { /* function `maybeAsync` returns true if callback will be called asynchronously */ return maybeAsync(data, result => sendResponse({ images: result })) }) Actual results: In some rare cases, the error "Error('this is impossible!')" will be thrown because the "data" parameter in callback is undefined. Expected results: The error should be never thrown because the `undefined` message cannot be replied. I'm unable to reproduce this issue. Also I'm getting this error reports only from Firefox users and it seems to disappear after restarting Firefox. I suspect this could be related to add-on upgrade mechanism as I tend to get more of these reports when I release new version (also there is no specific code running on upgrade in my add-on).
When you use the callback version of this API, you need to check runtime.lastError at the start of the callback. If lastError is defined, the response argument will always be undefined.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
Thank you for this info. I've released new version and now I can see the error object: message: "Could not establish connection. Receiving end does not exist." fileName: undefined lineNumber: 0 I'm not sure how to deal with this situation, if you could advice, I would be very happy. Also I received two more error reports where the "lastError" in the callback function was not set.
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.