Index: extensions/renderer/resources/runtime_custom_bindings.js |
diff --git a/extensions/renderer/resources/runtime_custom_bindings.js b/extensions/renderer/resources/runtime_custom_bindings.js |
index 60c3bd02e2a0106153c3e810397fe3fe592b7d7d..4e4a71d1e0a2c7b313c4d29d7123ac6b68bbc3ce 100644 |
--- a/extensions/renderer/resources/runtime_custom_bindings.js |
+++ b/extensions/renderer/resources/runtime_custom_bindings.js |
@@ -158,8 +158,16 @@ binding.registerCustomHook(function(binding, id, contextType) { |
if (unloadEvent.wasDispatched) |
throw new Error('Error connecting to extension ' + targetId); |
- if (!targetId) |
+ if (!targetId) { |
+ // runtime.id is only defined inside extensions. If we're in a webpage, |
+ // the best we can do at this point is to fail. |
+ if (!runtime.id) { |
+ throw new Error('chrome.runtime.connect() called from a webpage must ' + |
+ 'specify an Extension ID (string) for its first ' + |
+ 'argument'); |
+ } |
targetId = runtime.id; |
+ } |
var name = ''; |
if (connectInfo && connectInfo.name) |