Discovery of HTML Object Tag Methods and Properties

The Garmin Communicator API works through a browser plugin that is exposed to JS from a tag <object>

embedded in the HTML body.

I am trying to find any undocumented methods / properties of this object as I am building GWT-Garmin-API . Working with their JS API source I can see the official methods, but I want to find other methods / props. So far, I can't find a way to list them from an Object reference on the page.

No debugger I use shows such props. I was hoping there might be some kungfu reflection object that I am not aware of. Thank.

Update:

An example can be found in the Garmin Hello Device example .

From the console, iterate over the object you find from the following:

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

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

      

However, this won't use plugin methods like plugin.Unlock (), which you can easily call from the same console line.

+3


source to share


2 answers


There is no debugger that I am using shows props like this

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



Your in-in-loop approach to enumerating properties (and even heavier weapons like Object.getOwnPropertyNames

and Object.getPrototypeOf

) is flawed because something like this will show in your debugger.

If you really want to find "hidden" properties (I'm sure there aren't any), you will need to check every possible property name. Or look at their source, which may be hidden from you if it's a host object.

+2


source


In general, if you have a link to object

in javascript, you can iterate 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 can also try iterating over the prototypes of some Garmin classes, for example:



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

      

If it doesn't appear when you repeat one of these ways, it means the property is not exposed to JavaScript. Methods "called" that are not visible (for example plugin.unlock()

) are defined within the module itself. (When you call a method like this, you can think of it as passing a message from javascript directly to the plugin implementation.) The only way to find out the "list" of these methods is to access the source of the plugin code you are using. Javascript cannot request this list, unless the plugin has specifically implemented something to enable such functionality.

0


source







All Articles