New issue
Advanced search Search tips

Issue 590949 link

Starred by 6 users

Issue metadata

Status: Fixed
Owner:
Closed: Apr 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug-Regression



Sign in to add a comment

chrome.runtime.sendMessage responseCallback called with an argument on failures

Reported by mathieu....@gmail.com, Mar 1 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.64 Safari/537.36

Steps to reproduce the problem:
1. call chrome.runtime.sendMessage with a responseCallback function to send a message to a non-installed extension id 
2. observer arguments.length == 1 despite an error occurring

Example: https://jsfiddle.net/favbjrt2/

What is the expected behavior?
responseCallback is invoked with no arguments

What went wrong?
responseCallback was invoked with an undefined value for the first argument.

WebStore page: 

Did this work before? Yes Chrome 48

Chrome version: 49.0.2623.64  Channel: beta
OS Version: 10.0
Flash Version:
 

Comment 1 by rob@robwu.nl, Apr 5 2016

Cc: rob@robwu.nl
Status: WontFix (was: Unconfirmed)
It is not documented that arguments.length should be 0 when an error occurs.

To detect errors, you have to check whether chrome.runtime.lastError is set, and if so, extract the message via chrome.runtime.lastError.message.

PS. If you're curious: new behavior is caused by  https://crbug.com/439780#c4 .
I disagree, the published documentation says:
"If an error occurs while connecting to the extension, the callback will be called with no arguments and runtime.lastError will be set to the error message."
It specifically says "no arguments", not "a value of undefined". This is clearly an undocumented change in behavior.

Regarding detection of errors, checking lastError to figure out if an error occurred at all is quite counter-intuitive. In JavaScript, errors are indicated by exceptions thrown if synchronous and errors in callback / promise rejections if async. I'll pass on not having the error object in the callback, but there should be a way to know the async operation failed straight from the callback params.

Comment 3 by rob@robwu.nl, Apr 5 2016

Cc: -rob@robwu.nl
Labels: -OS-Windows -Type-Bug M-51 Type-Bug-Regression
Owner: rob@robwu.nl
Status: Started (was: WontFix)
That's indeed quite a strong statement in the documentation. I'll submit a patch to fix the callback in case anyone else is relying on it.

The canonical way to detect errors in extensions is via chrome.runtime.lastError in the callback. If you develop Chrome extensions, you should use chrome.runtime.lastError to detect extension-specific errors (and if you blindly pass untrusted parameters to the functions, also use try-catch since a mismatch in function parameter types causes an error to be thrown synchronously).
Project Member

Comment 4 by bugdroid1@chromium.org, Apr 6 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/ccb3bac625a150b6de7ed1855cfb3354f932792c

commit ccb3bac625a150b6de7ed1855cfb3354f932792c
Author: rob <rob@robwu.nl>
Date: Wed Apr 06 00:22:54 2016

Call chrome.runtime.sendMessage's callback without arguments upon fail

BUG= 590949 

Review URL: https://codereview.chromium.org/1860953003

Cr-Commit-Position: refs/heads/master@{#385346}

[modify] https://crrev.com/ccb3bac625a150b6de7ed1855cfb3354f932792c/extensions/renderer/resources/messaging.js

Comment 5 by rob@robwu.nl, Apr 6 2016

Status: Fixed (was: Started)

Sign in to add a comment