KangoExtensions / kango

Kango framework issue tracker
74 stars 7 forks source link

event.source.getId() on background message handler undefined in Safari #36

Closed martinth closed 11 years ago

martinth commented 11 years ago

I have an extension that uses code like this in the background script:

kango.addMessageListener('event', function (event) {
    kango.console.log(event.source.getId());
});

When run in Safari I get the following error: TypeError: 'undefined' is not a function (evaluating 'event.source.getId()'). In Chrome and Firefox the code runs fine and outputs the source tab id.

Additional information

Using the debugging console I can confirm that event.source and its prototype indeed don't have a method getId. In Chrome event.source is the following object:

kango.BrowserTab {_tab: Object, _ports: Object, superclass: function, _tab: null, _port: null…}

Whereas in Safari, event.source is printed as:

> event.source
Object
dispatchMessage: function (b, c) {a.target.page.dispatchMessage(b,c);return!0;}
__proto__: Object
akrylysov commented 11 years ago

If you want to get tab id you should use "target" field of event object. "source" is KangoMessageSource object.