janh˛ has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a bit of trouble with WWW::Mechanize::Firefox ( or, more specifically, MozRepl::RemoteObject, but I'm not completly sure if I just use W::M::F the wrong way).
Here's a short example that reproduces my problem with MozRepl 1.1 and Firefox versions 11 (Win 7 64 and Win XP) and 3.6.28 (Win XP) and the perl script on Win7 64, Winxp and debian linux. Perl-Versions: ActivePerl 5.10.0 on Windows, 5.10.1 on linux):

#!/usr/bin/perl use WWW::Mechanize::Firefox; my $ff = WWW::Mechanize::Firefox->new(activate => 1, autoclose => 0, ' +tab' => "current"); my @links = $ff->selector('a'); for my $link (@links) { my @keys = $link->__keys(); }

This fails in my setup with the following message: MozRepl::RemoteObject: TypeError: obj.hasOwnProperty is not a function at test-mozrepl.pl line 6

The problem seems to be in the javascript in MozRepl::RemoteObject, line 1289 in RemoteObject.pm (Version 0.30):

if (obj.hasOwnProperty(el)) {

I've tried to look into the js side, obj is of type "object" but obj.hasOwnProperty does not exist. I know too little about the interna of mozrepl and MozRepl::RemoteObject to guess smart checks I could do.

Any hints to what I am missing?
Please let me know which additional information might be helpful in diagnosing the problem.

Replies are listed 'Best First'.
Re: WWW::Mechanize::Firefox / MozRepl::RemoteObject
by Corion (Patriarch) on Mar 31, 2012 at 18:29 UTC

    It seems that DOM nodes do not necessarily support the .hasOwnProperty method. Until a new version of MozRepl::RemoteObject is released that does not rely on the object itself supporting hasOwnProperty, you will have to use this as a local patch workaround to MozRepl::RemoteObject:

    my $getKeys = $ff->application->repl->declare(<<'JS', 'list'); function(obj){ var res = []; for (var el in obj) { if (Object.hasOwnProperty.apply(obj,[el])) { res.push(el); }; } return res } JS

    But please do not use weird, undocumented methods to look inside elements. Use normal Perl hash methods:

    my @keys = keys %$link;

      Thank you, I will give that a try on monday.

      I've been using keys %$link at first but thought it might have been the cause of the problem, thus changing it. I'll see to change it accordingly.

      I tried and ran into some other problem. Thinking I might have broken something while searching myself, I went to grab the sources from cpan and check.

      I noticed you've already published a new version, installed that one: everything works great.

      Thank you very much!