Question

The Garmin Communicator API operates through a browser plugin that is exposed to JS from an <object> tag embedded in the HTML body.

I'm trying to find any undocumented methods/properties of this object as I build the GWT-Garmin-API. Working with their JS API source I can see the official methods, but I want to find any other methods/props. So far I cannot find a way to list these from a reference to the Object element in the page.

No debugger I use shows any such props. I was hoping there might be some Object reflection kungfu I don't know about. Thanks.

Update:

Example can be found at the Garmin Hello Device example.

From the console, iterate across the object you'll find from the following:

var plugin = document.getElementsByTagName('object')[0];

for(var prop in plugin) {
    console.log( prop );
}

However this will not find plugin methods like plugin.Unlock(), which you can easily call from the same console line.

Was it helpful?

Solution

No debugger I use shows any such props

Then there is no such thing, assuming those host objects are not implemented as Proxies.

Your approach of enumerating properties with a for-in-loop (and even heavier weapons such as Object.getOwnPropertyNames and Object.getPrototypeOf) is flawed, as anything visible like that would be shown in your debugger.

If you really want to find "hidden" properties (I'm very sure there are none), you would need to brute-force test all possible property names. Or have a look into their source, which might be hidden from you if it's a host object.

OTHER TIPS

In general, if you have a reference to object in javascript, you can loop over the properties and methods of that object using:

for(var property in object) {
    var value = object[property];
    console.log(property + ' = ' + value);
}

Given the source code you linked, you could also try iterating over the prototypes of some of the Garmin classes, like:

for(var property in Garmin.DevicePlugin.prototype) {
    //...
}

If it doesn't show up when you iterate in one of these ways, it means that the property is not exposed to javascript. "Callable" methods that that don't show up (like plugin.unlock()) are defined within the plugin itself. (When you call a method like this, you can think of it like passing a message from javascript directly into the implementation of the plugin.) The only way I know to find a "list" of these methods is to have access to the source code of the plugin that you are using. There is no way for javascript to ask for this list, unless the plugin has specifically implemented something to enable that kind of functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top